Validating data at the point of entry can be vital in cases where a value needs to be within a specific range, length, or format. This can inform users about the data required within fields and ensure accuracy.
Formulas using functions found in our Formula Cheat Sheet make this possible, and if you're looking for more granular control of alphanumeric text, Regular Expressions (Regex) are also supported.
In this Article
Standard Validation
The following standard options are available for validating user answers before looking into implementing custom formulas
Property | Description | What it looks like |
Required | On almost all field types. Enforces the user to provide an answer, eliminating the possibility of missing data for key fields in a form. This property also has a conditional logic option as to when a field becomes required or not. Example: If the answer to a safety checklist question is "failed", then you can use the conditional logic to make it a requirement that the user submits a photo of the item/asset being inspected. | |
Date Range | Allows a minimum and maximum date range to be set, preventing the user from selecting a date outside of it. | |
Number Range | On Numeric fields. Allows a minimum and maximum number range to be set, preventing the user from selecting a number outside of it. | |
Answer Format | On Text fields. Choose a common formatting rule to which the value entered conforms.
|
Validation Behavior
You have full control over how validation happens on every page of your form. The default behavior is "Inline", but you can change this by selecting a page field of your form and specifying what type of validation you want for that particular page.
- Inline
Validation occurs immediately after the user has entered a value into a field. - Page Change
Validation occurs when the user tries to navigate to another Page. - End of Form
Validation allows the user to leave this page while fields are still invalid, and validation checks are only performed when the entry is to be uploaded.
Custom Validation
The "Custom Validation" property is available on almost every field type. It allows a formula to be defined that checks whether or not a value is valid based on a business-specific rule or requirement.
If a formula result is TRUE, the value is valid. If FALSE, the value is invalid, and a default or custom validation message will be displayed in the app.
Formulas can be entered directly into the property or using the Formula Builder by clicking the hammer icon.
You can reference the data name of the field to which you are applying the validation without using the VAL() function, i.e., {{field1}} as opposed to VAL('field1'). VAL() is generally used in the Dynamic Value property of a field when its current value needs to be referenced to drive its new value.
The Custom Validation property requires a FALSE result to trigger (i.e., this value is FALSE, hence not valid, notify user) and, in turn, display the validation message.
With a FALSE result triggering the validation message, there are three common methods for creating a formula to do this, depending on your preference.
For example, let's trigger validation if a number is less than or equal to 100. Assuming the data name of the validated field is numeric.
One is to add a formula that checks if the value is what you need. {{numeric}} > 100 As long as the value entered is above 100, the result is TRUE(). As soon as it falls below or is equal to 100, the result is FALSE, triggering the validation. |
Two is to add a formula that checks if the value is not what you need. Encase a condition in a NOT() function. NOT({{numeric <= 100) The condition returns a TRUE result when the value is less than or equal to 100, and the NOT() inverts it to FALSE(), triggering the validation. |
Three is to add a formula where you can specify the result of a condition. Using an IF() function. IF({{numeric}} <= 100 , FALSE() , TRUE()) When the IF() function's condition is TRUE and the value is less than or is equal to 100, the IF() function returns FALSE, triggering the validation. |
Range Validation
Check if a value falls between a set range of values.
For example, a number needs to be greater than 100 and less than 200.
Validation formulas would look like this:
Examples:
{{dataname}} > 100 AND {{dataname}} < 200
or
NOT({{dataname}} <= 100) AND NOT({{dataname}} >= 200)
or
IF({{dataname}} <= 100, FALSE(), TRUE()) AND IF({{dataname}} >= 200, FALSE(), TRUE())
Length Validation
Check if a value's number of characters falls between a set range of values.
For example, a value's character length needs to be greater than 10 and less than 20.
Validation formulas would look like this:
Examples:
STRING-LENGTH({{dataname}}) > 10 AND STRING-LENGTH({{dataname}}) < 20
or
NOT(STRING-LENGTH({{dataname}}) <= 10) AND NOT(STRING-LENGTH({{dataname}}) >= 20)
or
IF(STRING-LENGTH({{dataname}}) <= 10 OR STRING-LENGTH({{dataname}}) >= 20, FALSE(), TRUE())
Format Validation
Check if a value's format starts with or contains a set of values.
For examples (1-3), validation formulas would look like this:
1. A value needs to start with the text 'AB-'.
Example:
STARTSWITH({{dataname}} , 'AB-')
2. A value needs to contain the text '@=at'
Example:
CONTAINS({{dataname}} , '@=at')
3. A value must not contain special characters (#, %, &).
Example:
NOT(CONTAINS({{dataname}} , '#') OR CONTAINS({{dataname}} , '%') OR CONTAINS({{dataname}} , '&'))
or
IF(CONTAINS({{dataname}} , '#') OR CONTAINS({{dataname}} , '%') OR CONTAINS({{dataname}} , '&') , FALSE() , TRUE())
Example: Social Security Number
To validate a field to format for social security number, with the format XXX-XX-XXXX, where each X is a number and dashes are explicit, consider using the following formula:
REGEX({{SSN}}, "^\d{3}-\d{2}-\d{4}$")
In the above, {{SSN}} is the name of the field containing your social security number. You may also decide to put in the following properties for your form, providing for the best end user experience:
Title Text: Social Security Number
Hint Text: Please use the format 123-45-6789
Placeholder Text: XXX-XX-XXXX
Validation Message: Social Security Number must be XXX-XX-XXXX
Download the Excel form attached and import it to a brand new form and try it out!
Example: Time
In cases where you want the user to manually enter a time into a field rather than using the date field, which will always pre-populate, consider using the following RegEx formula in a text field:
REGEX(., "^(0?[0-9]|1[0-9]|2[0-3])\:[0-5][0-9]$")
This uses the 24-hour format and will flag an error if the user enters an invalid time value.
Example: Multiple Email Addresses
The answer format of a text field enforces validation against the text field for a single email address. For cases where you wish to restrict input to potentially multiple email addresses, consider the below:
REGEX(., '^[\W]*([\w+\-.%]+@[\w\-.]+\.[A-Za-z]+[\W]*[,;]{1}[\W]*)*([\w+\-.%]+@[\w\-.]+\.[A-Za-z]+)[\W]*$')
This allows for multiple email addresses separated by either commas or semicommas.