Validation Rules 


In this Article
Related Articles

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.


Note: It is not suggested to use more than one validation type per field.

All validation rules can be accessed by clicking on a field, selecting Options and then selecting Validation Rules from the left-side option menu.


Limit Length of Input

This option allows you to set the maximum characters or words to be allowed in a text field. You can only define a limit for characters or words and not for both.

Required Fields

Users can be required to fill out a given field before submitting or proceeding to a form's next page.

To set a field as required:
  1. Select your question and click the Options button to open the editing sidebar
  2. Select Validation Rules from the sidebar.
  3. Check the corresponding box for This is a required field.
  4. This can also be accomplished by clicking the req'd icon after clicking on a field in your form.


Require an Email Address

To require a valid email address:
  1. Select a text input question and click the Options button to open the editing sidebar.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Email.
Note: An underscore in a domain of an email is most-likely a human error but FormAssembly's email validation will allow it to pass. However, Salesforce's validation will not accept the format of an underscore in the domain of an email.

Require Numbers Only

To require numbers only:
  1. Select a text input question and click the Options button to open the editing sidebar. Or, you can select your question with the sidebar open.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Number [0-9].

Require a Number Within a Range

Numbers can be limited within a range by doing the following:
  1. Select a text input question and click the Options button to open the editing sidebar.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Number [0-9].
  4. Enter the lower number in the From field and the higher number in the To field.

Require a Date and/or Time

To require a field to accept only a date:
  1. Select a text input field and click the Options button to open the editing sidebar.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Date, Time, or Date and Time.
Select the Date (with calendar) option if you'd like to allow respondents to use a calendar to select the date.

Require a Date and/or Time Within a Range

Date inputs can be limited to a specific range. To enter your range:
  1. Select a text input field and click the Options button to open the editing sidebar.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Date, Time, or Date and Time.
  4. Enter your beginning date in the From field and your ending date in the To field.

Require a Custom Format

Create your own formatting rules by using regular expressions, creating an automatic format, or by limiting the number of characters that can be entered into a field.
  1. Select your question and click the Options button to open the editing sidebar.
  2. Select Validation Rules from the sidebar.
  3. In the Expected Input Format menu, select Custom...
  4. Create your rules in the corresponding fields.

 

Auto-Format with a Mask


The auto-formatting can be used for a more simple pattern, such as a phone number or serial number.

For instance, let's say you have a serial number field and all of the serial numbers expected to be entered on your form start with M4K, then have 4 numbers and 2 letters. The mask would be M4K####$$, with # = numbers and $ = alphanumeric characters (letters or numbers).

Characters like commas, slashes, and dashes will all act like M4K and only function as place holders. The expected format will be visible once the field is selected.
 
Note: The Auto-Format with a Mask feature does not work reliably on Android phones. The best alternative would be to use a regular expression instead. Please contact support with any questions.

Validate with a Regular Expression


Regular expressions can help you define an expected pattern.

For instance, if you'd like a field to be formatted like currency, the regular expression /^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$/ will not allow any format except $3.99 through submission.

Example formats that will not be accepted are $3 or 3.99.

Suggestion: Use the custom validation message to let your respondents know what is expected in the field.
 

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've 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:
^ *([0-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}$
Zip Codes
To validate against a U.S. postal code in either a 5 digit format or a ZIP+4 format use the following validation:
^([0-9]{5})([\-]{1}[0-9]{4})?$
To validate against a U.S. postal code (ZIP and ZIP+4) and Canadian post codes, use the following validation:
^((\d{5}-\d{4})|(\d{5})|([AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d))$
Currency
To accept currency in any format (i.e. $100, $100.00, 100) use this regular expression:
/^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$/

To convert that value into a numerical value to send to Salesforce (i.e. to remove the $), you should mark that field as a variable, "amount" for the example below, and then create a calculated field with this calculation:
amount.toString().replace(/\$/,"").replace(/,/,"")
 
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.
Terms of Service · Privacy Policy