About data validation
Data validation can be used to display error alerts when users enter incorrect values into a form. Rather than checking for errors after a form is completed, data validation verifies values as the form is being filled out.
Working with data validation when filling out a form
Microsoft Office InfoPath 2003 automatically checks the data you type into a form and displays an error alert if the value does not match the condition specified by the data validation rule. The most common types of data validation include required entries, where you must enter a value; range checking, where the value you enter must fall into a certain range; and data types, where the value you enter must be a certain type, such as a number or date. If a value you enter does not match the specified condition, an error alert provides you with immediate feedback.
Error alerts can be either dialog box alerts or inline alerts. You can correct errors immediately, or you can use the commands on the Tools menu to navigate through and correct all the errors in a form at one time. Uncorrected errors are marked with a dashed red border or, for required entries, a red asterisk. If you save a form without fixing the errors, you will be reminded about the errors with a dialog box alert. You can save forms with validation errors, but you cannot submit them to a database or Web service.
Working with data validation when designing a form
Data validation is always associated with a specific control and occurs when a user fills out a form. Note that Office InfoPath 2003 verifies a condition by checking the value of the field that is bound to the control, not the control itself.
- Required controls Requires users to enter a value into a control.
- Data-type validation Requires users to enter a particular type of data, such as whole numbers or dates, into a control.
- Range checking Ensures that the value entered into a control is within the specified range. For example, range checking could limit an expense item to less than $500.
- Dynamic comparisons Compares values in different controls. For example, dynamic comparisons could require a shipping date to occur after an order date.
- Script-based validation Uses script to perform advanced validation on a control.
When you add data validation to a control, you can specify one of two types of error alerts to display to users:
- Inline alert Marks controls that contain invalid data with a dashed red border. The user can right-click the control to display a standard or custom error message.
- Dialog box alert Opens a dialog box with a custom error message when invalid data is entered into a control. If the user does not fix the error immediately, the control is marked with a dashed red border.
If a user saves a form without fixing errors, he or she is reminded with a dialog box alert. Users are allowed to save forms with validation errors, but they cannot submit invalid forms to a database or Web service.
If your form template is based on a pre-existing XML Schema, Office InfoPath 2003 automatically validates data entry based on the schema constraints. In some cases, these constraints are similar to or the same as the standard data validation available in Office InfoPath 2003; data-type validation, for example, is a kind of schema-based validation. In other cases, however, the pre-existing schema could contain more extensive validation, including pattern checking and advanced data types. Error alerts for schema-based validation appear as standard inline alerts.
To test a data validation constraint, including the conditions and error alerts, you can preview your form and enter valid and invalid data into the control you want to test. Error alerts will appear in the preview exactly as they appear to your users.
Note Conditional formatting is another effective way of responding to data entry. If you prefer to notify users with changes in color or text formatting, and you do not need to show an error alert, you can use conditional formatting for range checking and dynamic comparisons.