Examples
Every example below is live: edit the rules or the input and the result updates immediately. The examples run on the JavaScript implementation, and all implementations behave the same.
Registration form
rules
input
Validoutput
{
"name": "John",
"email": "john@mail.com",
"gender": "male",
"phone": "+22221212",
"password": "mypassword1",
"password2": "mypassword1"
}'required'is a shorter form of{ required: [] }.{ max_length: 10 }is a shorter form of{ max_length: [10] }.- See How it works for the full syntax.
Nested object
rules
input
Validoutput
{
"name": "Michael",
"phone": "0441234567",
"address": {
"city": "Kyiv",
"zip": 30552
}
}{ nested_object: {} }is a shorter form of{ nested_object: [{}] }.- Note that
zipis returned as a number: rules are expectations, see types coercing.
List of values
rules
input
Invaliderrors
{
"product_ids": [
null,
null,
"NOT_POSITIVE_INTEGER"
]
}List of objects
rules
input
Validoutput
{
"order_id": 10345,
"products": [
{
"product_id": 3455,
"quantity": 2
},
{
"product_id": 3456,
"quantity": 3
}
]
}List of different objects
The product_type field of each object selects the set of rules to apply.
rules
input
Validoutput
{
"order_id": 10455,
"products": [
{
"product_type": "material",
"material_id": 345,
"quantity": 5,
"warehouse_id": 24
},
{
"product_type": "service",
"name": "Clean filter"
}
]
}Output modification
rules
input
Validoutput
{
"email": "john.smith@example.com"
}trimremoves leading and trailing spaces.to_lcconverts the string to lower case.
Modifiers skip empty values and objects, so you can build a pipeline from any modifiers you like. See Modifiers.