Validation

Validation is available for the Text question type. Validation allows you to add rules that check the information entered in the field, and display an error if the entry does not match. For example, you can validate that the string entered is in the form of an email address, or is a number.

If the entry does not pass validation, the user is shown a message when the form is submitted, such as:

  • "Email address" is not in a valid format.

  • "Email address" is not the same in both fields.

Validation messages use the "Prompt" field for a question to identify the question to the user. Ensure you are using the prompt field to display the question name. It is also good practice to provide help text that indicates the required format.

Validation rules

For text questions, the Dual Entry option automatically adds two text fields and compares the results. the fields must have an identical value for the field to pass validation.

Screenshot: form question validation rule - email dual entry

Screenshot: dual entry required for an email text field

You can validate the these entry types automatically by including the following text in the Validation field:

Validation text Details
email Checks that the entry is in the form of an email address.
positiveInteger Checks that the value is a positive whole number.
integer Checks that the value is a whole number.
number Checks that the value is a number (does not contain text).

 

Add valid text field responses in the following form: (Answer1|Answer2), with valid entries separated by a pipe (|) character. For example, for the question below, "Enter your gender", enter (Male|Female) in the validation field to restrict entry to those 2 answers.

If the user completes the field with a different answer, the validation error message is shown:

Note
  • Valid entry words are case sensitive.
  • Spaces in front of or after a valid entry word will cause the entry to fail validation.
  • The validation message cannot be changed.
  • The value entered into the field must pass this validation before the person completing the form can move on to the next page.

Regular expressions for advanced validation

The validation field also accepts regular expressions (regex), which can be used to validate text entries or calculated values in formulas. Regular expressions are patterns that are used to match the format of a string. Regular expressions can check an entry for its length and format, such as checking that the entry is alphanumeric, is in the form of a URL, is the correct length, or is in a specific date format.

Regular expressions are extremely flexible and can be used to check for complex character combinations and values. The following examples provide some basic regex patterns that may be useful in validating text entries in your form. Search online for more regular expression examples and tutorials.

Regex pattern Details
[a-zA-Z] Checks that the entry is text only, with no numbers or special characters.
[a-zA-Z\s] Checks that the entry is text only, with no numbers or special characters, but also allows spaces and line breaks.
\d+(\.\d\d)? Checks that the entry contains either a whole number or a decimal with exactly 2 digits after the decimal point.
[^£$€¢] Checks that the entry contains any character other than those that follow the ^ character. This example excludes the following currency symbols: £ $ € ¢.
([^£$€¢])(\d+(\.\d\d)?) Checks that the entry contains either a whole number or a decimal with exactly 2 digits after the decimal point, and excludes the following currency symbols: £ $ € ¢.
[+]\d{9,15} Checks that the entry consists of between 9 and 15 digits and begins with a plus sign. Useful for validating telephone numbers in international format.
([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])) Checks that the entry is a date in the format YYYY-MM-DD.
^(?!000)([0-6]\d{2}|7([0-6]\d|7[012]))([ -]?)(?!00)\d\d\3(?!0000)\d{4}$

Matches a US social security number in the following formats:

  • 067-04-1120

  • 067 04 1120

  • 067041120