Basic Usage
Type Signature
Optional error message (string) or configuration object
Validation Methods
Length Validations
.min()
Enforces minimum string length.
Minimum length of the string
Custom error message or params object with
message property.max()
Enforces maximum string length.
Maximum length of the string
Custom error message or params object
.length()
Enforces exact string length.
Exact length required
Custom error message or params object
.nonempty()
Requires at least one character. Equivalent to .min(1).
Custom error message
Content Validations
.regex()
Validates string against a regular expression.
Regular expression pattern to match
Custom error message or params object
.includes()
Requires string to contain a substring.
Substring that must be present
Custom error message or params object with optional
position property.startsWith()
Requires string to start with a specific prefix.
Required prefix
Custom error message
.endsWith()
Requires string to end with a specific suffix.
Required suffix
Custom error message
Case Validations
.lowercase()
Validates that string contains only lowercase characters.
Custom error message
.uppercase()
Validates that string contains only uppercase characters.
Custom error message
Transform Methods
Transform methods modify the string value during parsing..trim()
Removes whitespace from both ends.
.toLowerCase()
Converts string to lowercase.
.toUpperCase()
Converts string to uppercase.
.normalize()
Normalizes the string using Unicode normalization.
Unicode normalization form (default: “NFC”)
.slugify()
Converts string to URL-friendly slug format.
Properties
.format
Returns the format string if the schema has a specific format, or null.
.minLength
Returns the minimum length constraint, or null if not set.
.maxLength
Returns the maximum length constraint, or null if not set.
Deprecated Format Methods
The following methods are deprecated in favor of standalone format schemas:.email()- Usez.email()instead.url()- Usez.url()instead.uuid()- Usez.uuid()instead.guid()- Usez.guid()instead.cuid()- Usez.cuid()instead.cuid2()- Usez.cuid2()instead.ulid()- Usez.ulid()instead.nanoid()- Usez.nanoid()instead.jwt()- Usez.jwt()instead.base64()- Usez.base64()instead.base64url()- Usez.base64url()instead.emoji()- Usez.emoji()instead.ipv4()- Usez.ipv4()instead.ipv6()- Usez.ipv6()instead.datetime()- Usez.iso.datetime()instead.date()- Usez.iso.date()instead.time()- Usez.iso.time()instead
Chaining
All validation and transform methods returnthis, enabling method chaining:
See Also
- String Formats - Specialized string format schemas
- Transforms - General transformation methods
- Custom Validations - Using
.refine()for custom logic