Adding validation rules to controls in a form template ensures that the data collected is accurate and consistent. When you add a text control, users can type anything into it. However, if you want to restrict users to entering an email address, then use a validation rule that ensures that what a user enters into the field matches the pattern of an email address, and prompt them to correct it if it is not.
In this article
Validation rule examples
The following are some examples of how to use validation rules in a form template:
- To let users know when the amount they enter for an expense item exceeds the approved amount.
- To ensure users enter a properly formatted phone number into a phone number box.
- To make sure a billing address is entered when a user does not select a check box that indicates that their billing address is the same as their shipping address.
Note Data validation rules prevent a user from submitting a form if any errors exist.
Ways to notify users about a validation error
Validation rules are designed to check for certain conditions within a form and, if those conditions are met, notify the users so that they can take corrective action. There are two ways that validation rules notify users about a validation error — ScreenTips and dialog boxes. A ScreenTip is always be associated with a validation error and appears when the user moves the mouse cursor over a control with a validation rule associated with it. You can also specify an additional dialog box message to be displayed when users enter invalid data.
By default, dialog boxes only appear when a user right-clicks a control with a validation error and then clicks Full error description in InfoPath Filler or clicks on the link in the validation ScreenTip in a Web browser. You can also configure the rule to display the dialog box automatically. This option only applies when filling out forms in InfoPath Filler when the user makes an invalid entry, and then tries to exit the control. Even when this option is selected, dialog box messages are not shown automatically when filling out forms in a Web browser.
Add a validation rule
Use the Add Rule button
Included, pre-defined validation rules can be added by using the Add Rule button. Do the following to quickly add a validation rule:
- Select a control.
- On the Home tab, in the Rules group, click Add Rule.
- Click the type of condition that the rule needs to meet in order to apply, such as Is Not an E-mail Address if you want the rule to make sure that the contents of the field are formatted like an email address.
- Click Show Validation Error.
Note Depending on the type of condition chosen, you might be asked to enter additional information.
- When finished, the Rules task pane appears and you can make any necessary changes to the rule.
Use the Rules task pane
Complete the following steps to add a validation rule from the Rules task pane:
- Create a validation rule.
- Click a control.
- If the Rules task pane is not visible then, on the Home tab, in the Rules group, click Manage Rules.
- Click New.
- Click Validation.
- In the Details for box, enter a name for the rule.
- Specify the conditions.
- Click None in the condition section.
- If the condition for your rule is based on a field, complete the following:
- Click field that the rule is based on.
- Click the operator, such as is equal to.
- Enter the value.
Note It is also possible to base a rule on an expression or a set of signable data. For more information about these advanced scenarios, see the corresponding section under Advanced condition scenarios.
- Click And to add another condition and repeat step 2 or click OK.
Note After adding a second condition, the And button is replaced with a box. Leave and selected if both the first and each subsequent condition needs to be true for the data validation to be applied. Otherwise, if only one of the conditions should be true for the data validation to be applied, select or.
- Specify a message.
- Enter the text in the ScreenTip box.
- If you want to add a more detailed message or enable an automatic dialog box message, do the following:
- Click Show more options.
- Click Show ScreenTip and dialog box message to enable the automatic dialog box message.
Note Only ScreenTips are displayed when filling out forms in a Web browser.
- In the Dialog box message box, enter the text.
This displays the Data Entry Pattern dialog box from which you can select from several pre-defined, standard patterns. If none of these patterns meets your needs, you can indicate a custom pattern. Custom patterns can require the use of special characters, which can be easily inserted by selecting them from the Insert special character box.
Advanced condition scenarios
The following are advanced scenarios that you can use when setting the condition of a data validation rule.
- Base a rule on an expression
An expression is a set of values, fields or groups, functions, and operators. Use an expression to check the value of a field, such as verifying a date that a user enters or the cost of an item entered into an expense report.
- Click The expression.
- Enter the expression.
Note For more information, see Add functions and formulas.
- Base a rule on a set of signable data
By basing a rule on a set of signable data, you can add an error message to a submit button if a user has not signed the form, thus helping to ensure that the form is signed before submitting. This condition is only supported in InfoPath Filler forms.
- Click Select set of signable data.
- In the Select Set of Signable Data dialog box, select the set of signable data, and then click OK.
- Click the desired condition, and then click the criteria.
Note For more information, see Digital Signatures in InfoPath 2010.
- Base a rule on a user’s role
You might have one form for all users but, depending on their role, require different information from each group of users. As a result, you can use a data validation error to display a validation error if a user that has been assigned to a particular role forgets to fill in a required field. User roles are only supported in InfoPath Filler forms.
- Click User’s current role from the first box.
- Click the operator, such as is equal to.
- Click the role or click Manage roles to manage user roles.
Top of Page