Custom Error Message Rules
The form designer includes the Error Messages tab. In the tab, you can configure form-level error message rules. That is, rules that dictate when to display custom error messages. You can configure the error message text and the condition under which to return the error message text. For example, when a user enters an invalid format for a number field, you can return an error message that says, “The number must be positive. Try again.” You would accomplish that with the following rule:
You might also want to add the field label or minimum value in the error message. The Display field includes a variable picker that allows you to add values dynamically. The condition you use determines the variables from which you can choose in the Display field. For example, you might want to customize the error message to identify the field and the minimum value a user can enter with an error message that says, “Number field accepts values greater than 0. Try again.” You would accomplish that with the following rule:
This document explores different ways in which you might want to customize field-level error message rules.
Setting an Error Message for a Maximum Value
You may want to notify a user that the value must be no larger than some maximum. For example, you might want to make sure the user does not enter a budget number greater than what you can support. The error message text might say, “Please enter a number smaller than 10,000.”
You can start by setting the Max in the Range allowed section of a Number field to the maximum budget. Then, you can create an error message rule that displays the error message text when a user enters a number greater than Max. You would accomplish that with the following rule:
Note: When you set a range, which includes a minimum and a maximum, use the “Value is not in range” error message. When you set only a minimum or a maximum, use the "Value exceeds maximum" or "Value exceeds minimum" option.
Setting Error Message Text with a Variable
In the previous example, you directly entered the value 10,000 into the error message text. You can also include a variable that is populated with whatever maximum you set for the field. Using the variable picker, you may have the error message text, “Please enter a number smaller than {_max}.”
The variables you can choose from in the Display field depend on the type of condition you set below the field. For example, if you say that the value is not in range, you will see a list of variables that relate to a range of numbers in the variable picker. If you say that the file cannot exceed the number limit, you will see a variable for the file number limit.
Setting an Error Message for a Regular Expression
The Regular expression for validation option is an Advanced setting for some fields in the Layout tab. The option allows you to use regular expressions to ensure a user enters a specified format in a field. In one case, you might want to ensure that the user enters all phone numbers as “###-###-####”, instead of “(###) ###-####” or “### ### ####”. You can set an error message rule that triggers when a user enters an incorrect format and lead them to enter the correct syntax. The error message text might say, “Please enter your phone number as ###-###-####.”
You can start by entering the regular expression in the Advanced setting for a Single Line field. The regular expression is “^[1-9]\d{2}-\d{3}-\d{4}”. Then, you can create an error message rule that displays the error message text when a user enters an improper format. You would accomplish that with the following rule:
Setting an Error Message for Invalid Date Formats
You may want to ensure a user enters a date properly. Instead of using a regular expression, you can set the Input has invalid format option in the When field. For example, you want to ensure a user enters the date format as “M/d/yyyy”. You set the date format for the Date field. Then, you can set an error message rule that triggers when a user enters an incorrect date format. The error message text might say, “Please enter a date as M/d/yyyy (e.g., 1/9/2018).” You would accomplish that with the following rule:
Ordering Error Messages
Forms uses various methods to determine the error message text to return when two or more rules have satisfied conditions for the same field. The first method is to return the most specific rule. For example, if rule #1 is for all fields and rule #2 is for Single Line fields, Forms returns rule #2 when the conditions overlap.
In rare cases, you may have two rules with the same level of specificity. In those cases, Forms returns the rule with the highest number. For example, if rule #1 and rule #2 match, Forms displays the error message text for rule #2.