Language: English
Validation rules restrict what a user is allowed to input in a field. If a user’s input violates the validation rule, the user won’t be allowed to save the record.
In this tutorial, we will add a simple validation rule to form collecting data about primary school students, specifically to the age field.
Step 1: Add a new form
- From the database page, click “Add Form”
- Enter “Student registration” as the Form Name
Add the name field
- Click “Add a field”
- From the list of field types, click “Text”
- Enter “Name” as the label
- Check “Key” in settings
Add the age field
- Move your cursor below the first field and click the “+” button
- From the list of field types, click “Quantity”
- Enter “Age” as the label
- Check “Required” in settings
- Check “Set validation rules”
- Scroll down to the “Validation Rules” section
- Where it says “Count as valid if”, change “Any” to “All”
- In the first row of the rules editor, change the predicate from “is” to “is greater than”, and set the value to “3”
- Click the “Add” button to add another row in the rules editor
- In the second row, change the predicate from “is” to “is less than” and set the value to “12”
- Enter a message in the “Validation error message” text box below the rules editor, for example “Age must be greater than 3 and less than 12”. The message is optional and limited to 1,024 characters. If you leave it blank, ActivityInfo shows a default message derived from the rules defined. The error message is translated in the same way as a field’s label and description.
Click “Done”
Click “Save” to save the form
Step 2: Test the data entry form
- From the Table View, click “Add Record”
- In the name field, enter “Oliver Twist”
- In the age field, enter “20”
- Click “Save record”
Because “20” violates the validation rule, ActivityInfo will not allow you to save the record. An error message will be displayed below the field:
Change the value to 6 and you then you can save the record.