Validators
Validators are rules that check attribute content when it is entered in the system and reject data that doesn't meet them. You can configure validators for each attribute field. To do this, open the attribute field settings and scroll down to the "Validation Rules" section.
The available validators can differ depending on the data type.
Types of validators
Each data type (opens in a new tab) has its own set of available validators. Below are all the validators you may encounter, across all data types.
Required field
The field must be filled in. No additional settings.
Trimming spaces around incoming data
Removes spaces at the beginning and end of the string. No additional settings.
Checking the string
Lets you configure parameters of a text value. In the additional settings, you can set a fixed string length or a range with minimum and maximum values.
URL verification
Accepts a string value only if it is a link. No additional settings.
Checking for a number
Checks whether the value is a number. In the additional settings, you can specify whether the number must be an integer and set its minimum and maximum values.
Rounding a number
This rule doesn't check that the value is numeric. Instead, it rounds the number according to the rules set in the additional settings. In the additional settings, you can specify the rounding precision and the rounding rule.
Email Verification
Checks that the value is a valid email address. No additional settings.
Default value
Sets a default value in the attribute if no value was entered. In the additional settings, you can specify the default value.
Given list screening
Checks whether the value entered in the attribute matches one of the values in the validator's list. In the additional settings, you can enter comma-separated values and enable logical negation.
Field mask
Checks whether the entered data matches the mask. In the additional settings, you can define the mask using special characters.
Regular expression validation
Checks whether the entered data matches a regular expression. In the additional settings, you can specify the regular expression. You can learn more about regular expressions here.
You can add several validators to one attribute field, but regular expression validation is not compatible with other value checks. Once a regular expression is added, the list no longer offers: Checking the string, Checking for a number, Default value, Given list screening, Field mask, Comparison, Logical, Email Verification, URL verification, Rounding a number, and Trimming spaces around incoming data.
The reverse also applies: if the field already has Trimming spaces around incoming data, the regular expression, Field mask, and Given list screening (as well as Size and Checking files) are not offered.
Comparison
Compares the value of the specified attribute with another value to make sure their relationship matches the comparison defined in the property. In the additional settings, you can specify the comparison type and value, and the comparison operator.
Logical
Checks whether the attribute value is a boolean. In the additional settings, you can configure how non-boolean values are interpreted.
Size
Checks the image size. In the additional settings, you can set the maximum width (Max X) and height (Max Y) of the image in pixels. There is no minimum size setting.
Checking files
Checks that the uploaded file meets the specified parameters. In the additional settings, you can set the minimum and maximum file size, the unit of measurement, and the list of allowed file extensions (Extensions).
Date and time range for restriction
Limits the values that can be selected in the attribute. Available for the "Date and Time", "Date", and "Time" types. In the additional settings, set the lower and upper bounds in the Minimum date and time value and Maximum date and time value fields. The field format matches the attribute type (date, time, or date with time). If the selected value is out of range, the user sees an error message.
Custom errors
You can add error text to any validator. The user sees this text when the validator rejects the data. Enter it in the validator settings, in the Custom error field. The text replaces the standard validation error message.
Examples
Email field validation example
In this example, the following is added for the string value:
- Removal of any spaces at the beginning and end of the string
- A check that the string is an email address
Password field validation example
In this example, the following is added for the string value:
- A check of the string's length and characters using a regular expression
Image field validation example
In this example, the following is added for the string value:
- A check of the image dimensions
- A check of the image file size
- A custom error