String validators
String validators
minLength
Validates that a text field meets a minimum character length.
| Property | Type | Required | Description |
|---|---|---|---|
value | number | Yes | Minimum required character length (inclusive) |
{
type: 'minLength',
value: 8,
message: 'Password must be at least 8 characters'
}maxLength
Validates that a text field does not exceed a maximum character length.
| Property | Type | Required | Description |
|---|---|---|---|
value | number | Yes | Maximum allowed character length (inclusive) |
{
type: 'maxLength',
value: 255,
message: 'Description cannot exceed 255 characters'
}regex
Validates that a field matches a specified regular expression pattern.
| Property | Type | Required | Description |
|---|---|---|---|
pattern | string | RegExp | Yes | Regular expression pattern to match |
{
type: 'regex',
pattern: '^[A-Z]{3}-\\d{4}$',
message: 'Must match format: ABC-1234'
}Validates that a field contains a properly formatted email address according to RFC standards.
{
type: 'email',
message: 'Please enter a valid email address',
options: {
allow_display_name: false,
require_tld: true,
allow_underscores: false
}
}Options:
All options are optional. The validator uses sensible defaults when options are not specified.
| Option | Type | Default | Description |
|---|---|---|---|
allow_display_name | boolean | false | Allow "Display Name <email@example.com>" format |
require_display_name | boolean | false | Require display name format |
allow_utf8_local_part | boolean | true | Allow non-English UTF8 characters in local part |
require_tld | boolean | true | Require top-level domain (e.g., .com, .org) |
ignore_max_length | boolean | false | Skip standard email length validation |
allow_ip_domain | boolean | false | Allow IP addresses as domain (e.g., user@192.168.1.1) |
domain_specific_validation | boolean | false | Enable provider-specific validation (e.g., Gmail rules) |
allow_underscores | boolean | false | Allow underscores in local part |
host_whitelist | string[] | - | Only allow emails from these domains |
host_blacklist | string[] | - | Reject emails from these domains |
blacklisted_chars | string | - | Reject emails containing these characters |
Examples:
Corporate emails only:
{
type: 'email',
options: {
host_whitelist: ['company.com', 'company.net'],
require_tld: true
}
}Allow internal emails:
{
type: 'email',
options: {
require_tld: false, // Allow user@localhost
allow_ip_domain: true
}
}Strict validation:
{
type: 'email',
options: {
domain_specific_validation: true,
allow_underscores: false,
blacklisted_chars: '!#$%'
}
}url
Validates that a field contains a properly formatted URL including protocol, domain, and optional path.
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
options.protocols | string[] | No | ['http', 'https'] | Allowed URL protocols |
options.require_protocol | boolean | No | false | Whether protocol is required |
options.require_host | boolean | No | true | Whether host is required |
options.require_valid_protocol | boolean | No | true | Whether protocol must be valid |
options.allow_underscores | boolean | No | false | Allow underscores in hostname |
options.allow_trailing_dot | boolean | No | false | Allow trailing dot in hostname |
options.allow_protocol_relative_urls | boolean | No | false | Allow URLs starting with // |
options.allow_query_components | boolean | No | true | Allow query parameters |
{
type: 'url',
options: {
protocols: ['https'],
require_protocol: true
}
}