Skip to content

Validation rules ​

The standard rules that every implementation supports. Open a rule to see how it works and to try it live, or filter the list by an error code to find the rule that returns it.

35 rules
Common rulesCheck that a value is present, or that it is an object.
String rulesCompare and measure strings. Numbers are validated as strings.
Numeric rulesCheck numbers and strings that look like numbers, and return them as numbers.
Special rulesEmails, URLs, dates, and comparison with another field.
MetarulesDescribe nested objects, lists and alternatives with other rules.
ModifiersChange the data. Modifiers never return errors.

Empty values are skipped ​

All standard rules skip empty values: a missing field, null and an empty string "". Only required, not_empty and not_empty_list check that a value is present. So the same rules work for optional fields:

js
first_name: { min_length: 10 }               // optional: the length is checked only if "first_name" is passed
first_name: ['required', { min_length: 10 }] // the name must be present and at least 10 characters long

Rules that expect a primitive value (a string, a number or a boolean) return FORMAT_ERROR when they receive an object or a list. See Error codes.

Learn more ​