Teki
Rules

String

Validate text fields and chain string-specific constraints.

Use string("field") for fields that must be strings.

Teki schema = Teki.fromRules(
    string("email").required().email().trim(),
    string("username").alphanum().min(3).max(24),
    string("website").optional().url()
);

Available methods

MethodPurpose
required()Reject missing values
optional()Skip validation when the value is missing
email()Validate email addresses
url()Validate URLs
pattern(String)Validate with a regular expression
alphanum()Allow only letters and digits
ip()Validate IPv4 or IPv6 addresses
ipv4()Validate IPv4 addresses only
ipv6()Validate IPv6 addresses only
mac()Validate MAC addresses
creditCard()Validate credit card numbers
min(int)Require a minimum length
max(int)Require a maximum length
between(int, int)Require a length range
length(int)Require an exact length
trim()Trim surrounding whitespace
uuid()Validate UUID format
phone()Validate phone numbers (E.164 format)
slug()Validate URL slugs
base64()Validate standard base64
base64(boolean)Validate base64 (standard or URL-safe)
semver()Validate semantic versions
iban()Validate IBANs
notBlank()Reject null and whitespace-only strings
oneOf(String...)Require the value to be in a fixed set
defaultValue(String)Fill a missing value
custom(Rule)Attach a custom rule

Annotation equivalent

String fields can use annotations such as @Required, @Email, @Url, @Pattern, @Between, @Trim, @Default, @Uuid, @Phone, @MacAddress, @Slug, @Base64, @SemVer, @Iban, @NotBlank, and @OneOf.

On this page