Rules Overview
Browse Teki's built-in builders, presence rules, string rules, and range rules.
Import the builder entry points from Rules when using the fluent API:
import static dev.ditsche.teki.rule.builder.Rules.*;Rules are organized around the shape of the field first, then the constraints you add to that field.
Builders
String
Validate text fields and chain string-specific constraints.
Number
Validate numeric fields with min, max, size, and defaults.
Boolean
Validate boolean values with true or false expectations.
Array
Validate arrays, iterables, array elements, and arrays of objects.
Object
Validate nested objects with child field rules.
Temporal
Validate date and time fields with past, future, and boundary rules.
Presence and normalization
Required
Reject missing values.
Optional
Skip validation when supported fields are missing.
Default
Fill missing values with a fallback.
Trim
Normalize string values by trimming surrounding whitespace.
String validation
Validate email addresses.
URL
Validate URLs.
Pattern
Validate strings with a regular expression.
Alphanumeric
Allow only letters and digits.
IP Address
Validate IP addresses.
Credit Card
Validate credit card numbers.
UUID
Validate UUID strings.
Not Blank
Reject null and whitespace-only strings.
One Of
Restrict a field to a fixed set of allowed values.
Size and range
Min
Require a minimum value, length, or size.
Max
Require a maximum value, length, or size.
Length
Require an exact length.
Between
Require a value, length, or size to fall within a range.
Positive
Require a number to be greater than zero.
Negative
Require a number to be less than zero.
Temporal
Past
Require a date in the past.
Future
Require a date in the future.
Past or Present
Require a date in the past or equal to now.
Future or Present
Require a date in the future or equal to now.
Before
Require a date before a fixed boundary.
After
Require a date after a fixed boundary.
Example
Teki schema = Teki.fromRules(
string("email").required().email().trim(),
string("username").required().alphanum().min(3).max(24),
number("age").min(13),
array("roles").elements().string().min(2).max(32)
);