Index |
---|
Shorthands |
Array data validation |
Traversable data validation |
Examples |
General | Type | Range | Pattern | Date |
---|---|---|---|---|
filled | array | between | alpha | date |
nullable | boolean | max | alpha_dash | datetime |
required | float | min | alpha_num | date_format |
integer | ||||
string | in | |||
regex | ||||
url |
The field under validation must be entirely alphabetic characters. Shorthand for pattern: [a-zA-Z]
The field under validation may have alpha-numeric characters, as well as dashes and underscores. Shorthand for pattern: [a-zA-Z0-9_-]
The field under validation must be entirely alpha-numeric characters. Shorthand for pattern: [a-zA-Z0-9]
The field under validation must be a PHP array.
Arguments: <digit>,<digit>
The constraint has different implementations based on the value type.
- If the value has a date constraint (date, datetime or datetime_format), the
<digit>
arguments accepts nowDateTime
allowed formats. The value must be between than the supplied<digit>
arguments. More information in the Symfony Validation documentation. - If the value has a numeric constraint (integer or float), it must lie between the two values.
- Otherwise, the length of the value must be between the supplied values.
Example:
- string must have minimum length of 2 and maximum length of 6:
between:2,6
- integer must have a value between 2 and 6 or less:
integer|between:2,6
- date must be between
2010-01-01
and2011-01-01
:date|between:2010-01-01,2011-01-01
The value must be bool or castable to bool.
- allowed
true
values:1, '1', 'on', true
- allowed
false
values:0, '0', 'off', false
Note: can also be written as bool
The value must be a valid date of format Y-m-d
The value must be a valid date+time of format Y-m-d H:i:s
Argument: <pattern>
The value must match the given date pattern. See DateTime::createFromFormat() for formatting options.
The value must be a valid email.
The value must be filled and not be null (except if nullable is also set). If the value is an empty string, this validation rule fails.
The value must be a float or castable to float.
- example of allowed values:
-1, 1, -1.1, 1.1, '1.1', '-1.1', '.1', '1.', '1', '-1'
Arguments: string,string,...
The field under validation must be included in the given list of values.
Example:
required|in:foo,bar
The value must be an integer or castable to int.
- example of allowed values:
1, -1, '1', '-1'
Note: can also be written as int
Argument: <digit>
The constraint has different implementations based on the value type.
- If the value has a date constraint (date, datetime or datetime_format), the
<digit>
argument accepts nowDateTime
allowed formats and the value must be less or equal than the supplied argument. More information in the Symfony Validation documentation. - If the value has a numeric constraint (integer or float), it must be smaller than the supplied value.
- Otherwise, the length of the value must be smaller than the supplied value.
Example:
- string with maximum length of 6:
max:6
- integer which has to be 6 or less:
integer|max:6
- limit the given date by:
date|max:+10 days
Argument: <value>
The constraint has different implementations based on the value type.
- If the value has a date constraint (date, datetime or datetime_format), the
<digit>
argument accepts nowDateTime
allowed formats and the value must be greater or equal than the supplied<digit>
argument. More information in the Symfony Validation documentation. - If the value has a numeric constraint (integer or float), it must be bigger than the supplied value.
- Otherwise, the length of the value must be bigger than the supplied value.
Example:
- string with minimum length of 6:
min:6
- integer which has to be 6 or higher:
integer|min:6
- limit the given date by:
date|min:now
The value can be null
.
Argument: <pattern>
The value must match the supplied regex. The full string will be passed to the preg_match function.
Example:
- match all strings starting with 'ab':
regex:/^ab.*$/
By default in a data set a key/value-pair can be left out. Add required
to make the key/value-pair mandatory.
Example:
[
'a' => 'required|string',
'b' => 'integer'
]
Passes:
['a' => 'a'];
Fails:
['b' => '1'];
The value must be a string.
The value must be a valid url.