Validation tests

  • email(message)
  • exact(limit, message)
  • integer(message)
  • matches(pattern, message)
  • max(limit, message, exclusive?)
  • maxDate(limit, message, exclusive?)
  • min(limit, message, exclusive?)
  • minDate(limit, message, exclusive?)
  • oneOf(values, message)
  • required(message, nullable?)
  • url(message, protocols?)

email(message)

Ensures the value follows an email address format. Wraps the matches validation test. Only works with the string validation type.

message is a string or function returning a string with the validation error message.

exact(limit, message)

Ensures value is of an exact size. Works with string, array, and number validation types and verifies string length, array length, and numeric value respectively. An additional amount field representing the size is passed to the validation error message.

limit is the string length, array length, or numeric value to compare against. It's passed to the validation error message and also aliased as exact for convenience.

message is a string or function returning a string with the validation error message.

integer(message)

Ensures value is an integer number. Only works with the number validation type.

message is a string or function returning a string with the validation error message.

matches(pattern, message)

Ensures value matches the specified pattern. Only works with the string validation type.

pattern is the regular expression to match against.

message is a string or function returning a string with the validation error message.

max(limit, message, exclusive?)

Ensures value is of at most a certain size. Works with string, array, and number validation types and verifies string length, array length, and numeric value respectively. An additional amount field representing the size is passed to the validation error message.

limit is the string length, array length, or numeric value to compare against. It's passed to the validation error message and also aliased as max for convenience.

message is a string or function returning a string with the validation error message.

exclusive makes the comparison exclusive instead of exclusive when true. Defaults to false.

maxDate(limit, message, exclusive?)

Ensures value is on or before the specified date. Only works with the date validation type.

limit is the date to compare against. May be a Date, number, or ISO date string. It's passed to the validation error message and also aliased as max for convenience. Uses the internal date parser.

message is a string or function returning a string with the validation error message.

exclusive makes the comparison exclusive instead of exclusive when true. Defaults to false.

min(limit, message, exclusive?)

Ensures value is of at least a certain size. Works with string, array, and number validation types and verifies string length, array length, and numeric value respectively. An additional amount field representing the size is passed to the validation error message.

limit is the string length, array length, or numeric value to compare against. It's passed to the validation error message and also aliased as min for convenience.

message is a string or function returning a string with the validation error message.

exclusive makes the comparison exclusive instead of exclusive when true. Defaults to false.

minDate(limit, message, exclusive?)

Ensures value is on or after the specified date. Only works with the date validation type.

limit is the date to compare against. May be a Date, number, or ISO date string. It's passed to the validation error message and also aliased as min for convenience. Uses the internal date parser.

message is a string or function returning a string with the validation error message.

exclusive makes the comparison exclusive instead of exclusive when true. Defaults to false.

oneOf(values, message)

Ensures value is one of the provided values. Works with string, date, number, and boolean validation types.

values should be an array of allowed values. May be strings, dates, numbers, or booleans.

message is a string or function returning a string with the validation error message.

required(message, nullable?)

Ensures value is not one of: undefined, null, NaN, an empty string, or an invalid date. Works with all types.

message is a string or function returning a string with the validation error message.

nullable allows null to be a valid value when true. Defaults to false.

url(message, protocols?)

Ensures value is a valid URL. Only works with the string validation type.

message is a string or function returning a string with the validation error message.

protocols may be an array of allowed URL protocols, e.g. https:, mailto:.