Input Validation

Important Remark: The purpose of input validation is to help your respondents provide the desired answers in the expected format. It is an aid, and it is not designed to be foolproof. There are ways one can bypass the validation and, although rare in a normal use case, invalid responses should not be unexpected.

Required Fields

You can mark a field as required in the Form Builder. Select the question in the form outline, and in the 'Properties' panel, check the 'Answer required' box (in the 'Input Validation' section).

Required Formats

The 'format' option is available for free-text questions only (single-line text input, multi-line text input, password field). You can select one of the predefined format, or provide your own using a custom regular expression.

Custom Validation Using Regular Expressions

What is a regular expression?

A regular expression is a way of searching for a pattern in text (for example, a date in the format mm/dd/year). In FormAssembly, you can use regular expressions to validate that the user input conforms to an expected pattern, and provide a customized error message if the answer is in an incorrect format.

How can I use regular expressions in my forms?

In the Form Builder, select the desired question in the outline. In the properties panel, make sure that you allow a free-text answer (single-line text input or multi-line text input). In the "Input Validation" section, select "custom (regular expression)" from the drop down menu. Type your regular expression in the first input box, and the error message you would like to display in the second. Answers that are not in the same format as your regular expression will not validate and your custom error message will appear.

Useful Regular Expressions for Forms

Crafting regular expressions is a difficult and somewhat arcane art. It is usually best to copy&paste an existing expression than trying to come up with your own. We listed a few useful expressions below and provided links to third-party resources where you can find a lot more.

Date

To require a response in the format mm/dd/year, use this regular expression:
(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]\d\d\d\d$

To require a response in the format dd/mm/year, use this regular expression:
(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]\d\d\d\d$

Time

To require a response that is a time of day (12 hour format), use this regular expression:
^ *(1[0-2]|[1-9]):[0-5][0-9] *(a|p|A|P)(m|M) *$

Phone Numbers

To require a response that is a valid US phone number, use this regular expression:
^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$

Where can I get more information on regular expressions?

If you wish to further customize your form validation with regular expressions, these sources may be helpful. For a tutorial in regular expressions, click here. The Regular Expression Library is a searchable database of regular expressions that have been created. If you create regular expressions and would like to check that they work correctly, use a checker like this one.