Ivandt logo

String validators

String validators

minLength

Validates that a text field meets a minimum character length.

PropertyTypeRequiredDescription
valuenumberYesMinimum 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.

PropertyTypeRequiredDescription
valuenumberYesMaximum 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.

PropertyTypeRequiredDescription
patternstring | RegExpYesRegular expression pattern to match
{
  type: 'regex',
  pattern: '^[A-Z]{3}-\\d{4}$',
  message: 'Must match format: ABC-1234'
}

email

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.

OptionTypeDefaultDescription
allow_display_namebooleanfalseAllow "Display Name <email@example.com>" format
require_display_namebooleanfalseRequire display name format
allow_utf8_local_partbooleantrueAllow non-English UTF8 characters in local part
require_tldbooleantrueRequire top-level domain (e.g., .com, .org)
ignore_max_lengthbooleanfalseSkip standard email length validation
allow_ip_domainbooleanfalseAllow IP addresses as domain (e.g., user@192.168.1.1)
domain_specific_validationbooleanfalseEnable provider-specific validation (e.g., Gmail rules)
allow_underscoresbooleanfalseAllow underscores in local part
host_whiteliststring[]-Only allow emails from these domains
host_blackliststring[]-Reject emails from these domains
blacklisted_charsstring-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.

PropertyTypeRequiredDefaultDescription
options.protocolsstring[]No['http', 'https']Allowed URL protocols
options.require_protocolbooleanNofalseWhether protocol is required
options.require_hostbooleanNotrueWhether host is required
options.require_valid_protocolbooleanNotrueWhether protocol must be valid
options.allow_underscoresbooleanNofalseAllow underscores in hostname
options.allow_trailing_dotbooleanNofalseAllow trailing dot in hostname
options.allow_protocol_relative_urlsbooleanNofalseAllow URLs starting with //
options.allow_query_componentsbooleanNotrueAllow query parameters
{
  type: 'url',
  options: {
    protocols: ['https'],
    require_protocol: true
  }
}