Validation
Basic and Advanced elements have the option for you to apply validation to them. This allows you to force the form user to provide an answer, specify criteria that must be met, and provide custom error messages.
On this page:
Types of Validation
There are different types of validation available, depending on the element selected. You can apply validation when the element is created or later in the element's settings.
Note: The email and CAPTCHA elements automatically have validation applied.
Force Checked
This forces the form user to check the element before submitting. This is commonly used for Terms & Conditions.
Force Value
This forces the form user to provide values to elements such as DoB, Date Picker and Country Select.
Validation Rule
A validation rule has two different forms of complexity. It allows you to simply force a value or provide a regular expression so that the value meets a certain criteria.
- Not empty: The form field must contain a value of some kind in order for the form to be submitted.
- Advanced: This option allows you to define a type of value required in the field from the user, such as particular characters or words, using a regular expression
Regular Expression
Regular expressions allow complex pattern matching, for example you could specify a customer number in a particular format, or a telephone number.
This example shows how you could match a UK postcode:
^[a-z]{2}\d{1,2} ?\d{1,2}[a-z]{2}$
Which would match a string starting with two letters [a-z]{2}, one or two numbers \d{1,2}, an optional space ( ?), and that ends with one or two numbers \d{1,2}, and two letters [a-z]{2}.
Custom Error Message
If you use validation on an element you will be shown the custom error message text area. This allows you to provide a custom error message if validation of an element fails.
You can leave this blank and the default error message will show: '<label>' is invalid'
Elements and their Validation Types
The following table will display the element, whether it is Advanced or Basic, and the type of validation it has: Force value, Force Checked, Validation Rule, Automatic.
Element | Element Type | Validation Type |
---|---|---|
CAPTCHA | Advanced | Automatic |
Checkbox | Basic | Force Check |
Country Select | Advanced | Force Value |
DoB | Basic | Force Value |
Date Picker | Advanced | Force Value |
Basic | Automatic | |
Postal Code | Advanced | Automatic |
Radio | Basic | Force Value |
Select | Basic | Force Value |
Text Area | Basic | Validation Rule |
Text Box | Basic | Validation Rule |
FAQ
Why can't I add validation to the email element?
The validation on an email element is automatic, and the user must enter an email address in order to submit the form.
What kind of regular expression syntax is supported?
Adestra supports PCRE.