Validation rules do not have an implicit 'required'. If a field is undefined or an empty string, it will pass validation. If you want a validation to fail for undefined or '', use the required rule.
The field under validation must be yes, on, 1 or true. This is useful for validating "Terms of Service" acceptance.
The field under validation must be after the given date.
The field unter validation must be after or equal to the given field
The field under validation must be entirely alphabetic characters.
The field under validation may have alpha-numeric characters, as well as dashes and underscores.
The field under validation must be entirely alpha-numeric characters.
The field under validation must be an array.
The field under validation must be before the given date.
The field under validation must be before or equal to the given date.
The field under validation must have a size between the given min and max. Strings, numerics, and files are evaluated in the same fashion as the size rule.
The field under validation must be a boolean value of the form true
, false
, 0
, 1
, 'true'
, 'false'
, '0'
, '1'
,
The field under validation must have a matching field of foo_confirmation. For example, if the field under validation is password, a matching password_confirmation field must be present in the input.
The field under validation must be a valid date format which is acceptable by Javascript's Date
object.
The field under validation must be numeric and must have an exact length of value.
The field under validation must be numeric and must have length between given min and max.
The given field must be different than the field under validation.
The field under validation must be formatted as an e-mail address.
The field under validation should be a hexadecimal format. Useful in combination with other rules, like hex|size:6
for hex color code validation.
The field under validation must be included in the given list of values. The field can be an array or string.
The field under validation must have an integer value.
Validate that an attribute is no greater than a given size
Note: Maximum checks are inclusive.
Validate that an attribute is at least a given size.
Note: Minimum checks are inclusive.
The field under validation must not be included in the given list of values.
Validate that an attribute is numeric. The string representation of a number will pass.
The field under validation must be present in the input data but can be empty.
Checks if the length of the String representation of the value is >
The field under validation must be present and not empty if the anotherfield field is equal to any value.
The field under validation must be present and not empty unless the anotherfield field is equal to any value.
The field under validation must be present and not empty only if any of the other specified fields are present.
The field under validation must be present and not empty only if all of the other specified fields are present.
The field under validation must be present and not empty only when any of the other specified fields are not present.
The field under validation must be present and not empty only when all of the other specified fields are not present.
The given field must match the field under validation.
The field under validation must have a size matching the given value. For string data, value corresponds to the number of characters. For numeric data, value corresponds to a given integer value.
The field under validation must be a string.
Validate that an attribute has a valid URL format
The field under validation must match the given regular expression.
Note: When using the regex
pattern, it may be necessary to specify rules in an array instead of using pipe delimiters, especially if the regular expression contains a pipe character.
For each backward slash that you used in your regex pattern, you must escape each one with another backward slash.
forms.useRules({
name: 'required|size:3',
salary: ['required', 'regex:/^(?!0\\.00)\\d{1,3}(,\\d{3})*(\\.\\d\\d)?$/'],
yearOfBirth: ['required', 'regex:/^(19|20)[\\d]{2,2}$/']
})
The valid data will be like,
{
name: 'Doe',
salary: '10,000.00',
yearOfBirth: '1980'
}
form.useRules({
age: ['required', { 'in': [29, 30] }],
name: [{ required_if: ['age', 30] }]
});
The valid data will be like,
{
age: 30,
name: ''
}