Validation

Validation is available for the Text question type in Sage. Validation allows you to add rules that check the information you enter in the field, and display an error if the entry doesn't match.

For example, you can validate that the string you entered is in the form of an email address, or is a number.

If the entry doesn't pass validation, the system shows the user a message when they submit the form, such as:

  • "Email address" isn't in a valid format

  • "Email address" isn't the same in both fields

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

Validation rules

For text questions, the Dual Entry option adds two text fields automatically 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 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 (doesn't 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 two answers.

Screenshot: Gender input validation example

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

Annotated screenshot: Validation error example when input does not match validation

Note
  • Valid entry words are case-sensitive
  • Spaces in front of or after a valid entry word will cause the entry to fail validation
  • You can't change the validation message
  • The value you enter into the field must pass this validation. This is 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 you can use to validate text entries or calculated values in formulas. Regular expressions are patterns that we use to match the format of a string. Regular expressions can check an entry for its length and format. For example, checking the entry is alphanumeric, in the form of a URL, the correct length, or in a specific date format.

Regular expressions are flexible and you can use them to check for complex character combinations and values. The following examples provide some useful basic regex patterns for 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 two digits after the decimal point.
[^£$€¢] Checks that the entry contains any characters 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 two digits after the decimal point. Excludes the following currency symbols: £ $ € ¢.
[+]\d{9,15} Checks that the entry consists of between nine 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