Validations help to ensure that only valid data is saved into your database. This guide demonstrates how to validate the state of objects before their database insertion using the validation feature of a form.
After reading this reference, you will know:
Below is a simple validation example:
A form is only considered valid if the
You can use the validation types detailed in this section.
This validation is used when the same value must be entered twice.
Setting it to
As an illustration, when the
This behaviour means you must add the
The default error message for this validator is the 'doesn't match %{attribute}'.
Checks if the provided value is a valid email address.
Tries to match the provided value with regexp defined in
A blank value will produce a validation error when
The possible length constraint options are:
Validation | Description | Default error message |
---|---|---|
Cannot have less than the specified number. | is too short (minimum is %{count} characters) | |
Cannot have more than the specified number. | is too long (maximum is %{count} characters) | |
The attribute length must be equal to the given number. | is the wrong length (should be %{count} characters) |
Available options are:
Validation | Description | Default error message |
---|---|---|
Input must be greater than the set value. | must be greater than %{count} | |
Input must be greater than or equal to the set value. | must be greater than or equal to %{count} | |
Input must be equal to the set value. | must be equal to %{count} | |
Input must be less than the set value. | must be less than %{count} | |
Input must be less than or equal to the set value. | must be less than or equal to %{count} | |
Input must be other than the set value. | must be other than %{count} | |
Input must be an odd number if set to |
must be odd | |
Input must be an even number if set to |
must be even |
Datetime is a date with the exact time down to the second. For example,
The system can convert human phrases (for example,
Note:
The possible date constraint options are:
Validation | Description |
---|---|
Must be at this exact datetime. | |
Must be earlier than provided datetime. | |
Must be later than provided datetime. | |
Must be exactly the datetime or earlier. | |
Must be exactly the datetime or later. |
All default error messages are in a format
The possible date constraint options are:
Validation | Description |
---|---|
Must be at this exact date. | |
Must be earlier than provided date. | |
Must be later than the provided date. | |
Must be exactly the date or earlier. | |
Must be exactly the date or later. |
All default error messages are in a format
It is possible to validate attributes based on the state of other attributes from the form.
This section details common validation options you can use on your code.
It is possible to overwrite the default message with additional fields:
The
Allows passing an empty string.
When a form validation error is raised, an error message is added to the
If you need errors for a particular field, access them through:
Example:
Each error message can be translated with the Insites translation mechanism.
Please visit Translations: System Messages for more information.
Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.