Data validation (data validation: The process of testing the accuracy of data; a set of rules you can apply to a control to specify the type and range of data that users can enter.) can be used to display error alerts when users enter incorrect values into a control (control: A graphical user interface object, such as a text box, check box, scroll bar, or command button, that lets users control the program. You use controls to display data or choices, perform an action, or make the user interface easier to read.). You can also write code to
perform advanced validation. Note
that Microsoft Office InfoPath 2003 verifies a condition by checking the value of the field (field: An element or attribute in the data source that can contain data. If the field is an element, it can contain attribute fields. Fields store the data that is entered into controls.) that is bound (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) to a control, not the control itself.
Require a specific type of data
- In design mode, double-click the control whose
data type you want to change.
- On the Data tab in the Control Properties dialog box, click the data type you want in the
Data type
box.
Note If a user types a value with the wrong data type, a standard inline alert (inline alert: A data validation alert that marks controls that contain invalid data with a dashed red border. Users can right-click controls to display custom error messages.) will appear.
Note If
your form is based on a sample form or a pre-existing XML Schema (XML Schema: A formal specification, written in XML, that defines the structure of an XML document, including element names and rich data types, which elements can appear in combination, and which attributes are available for each element.),
you may not be able to change the data type.
Require a specific value or range of values
- In design mode, select the control for
which you want
the
validation to occur, and then click
Data Validation on the
Format menu.
- In the
Data Validation dialog box, click
Add.
- In the
If this condition is true
boxes, enter the condition.
- To add additional conditions, click
And, and then, in the rightmost box under
If this condition is true,
do one of the following:
- To show the error alert only when both conditions are true,
click
and.
- To show the error alert when one or both conditions are true,
click
or.
- In the
Error alert type box, click the type
of error alert you want to display to users.
- In the ScreenTip box, type the text you want to display when a user points to the control or right-clicks the control.
- In the Message box, type the text you want to display in the dialog box either immediately (if you chose a dialog box alert) or when the user requests more details (if you chose an inline alert).
Require a specific pattern, such as a phone number
- In design mode, select the control for
which you want
the
validation to occur, and then click
Data Validation on the
Format menu.
- In the
Data Validation dialog box, click
Add.
- Make sure the first box under
If this condition is true contains the control's field.
- In the second box, click does not match pattern.
- In the third box, click Select a pattern.
- In the Data Entry Pattern dialog box, do one of the following:
- In the Standard patterns box, select one of the patterns.
- In the Custom pattern box, enter a pattern. You can type directly in the box. To insert special characters in the pattern, click the character in the Insert special character box.
- Click OK.
- In the
Error alert type box, click the type
of error alert you want to display to users.
- In the ScreenTip box, type the text you want to display when a user points to the control or right-clicks the control.
- In the Message box, type the text you want to display in the dialog box either immediately (if you chose a dialog box alert) or when the user requests more details (if you chose an inline alert).
Add code-based validation
To create an event handler
in InfoPath, you must associate the event with
the correct field,
and then write the code in Microsoft Script Editor (MSE) (Microsoft Script Editor (MSE): A programming environment used to create, edit, and debug Microsoft JScript or Microsoft VBScript code in an InfoPath form.) or Microsoft Visual Studio .NET 2003. Because the event
handler is referred to in the form
definition (.xsf)
file (form definition file: An XML file with an .xsf extension that contains information about all other files and components used within a form, including user interface customizations, XML Schemas, views, business logic, events, and deployment settings.),
you should not create a new handler entirely from within MSE or Visual Studio. In addition, you
should not modify the event handler name or its arguments.
- In design mode, select the control for
which you want the
validation to occur, and then click
Data Validation on the
Format menu.
- In the
Events list in the
Data Validation dialog box, click the
event you want to create or modify, and then click
Edit.
Note This opens
MSE or Visual Studio and
positions the cursor at the specified event.
- In
MSE or Visual Studio, type
the code that you want to run when the event occurs.
Note The information in this topic may not apply if you are working with a form designed using Microsoft Office InfoPath 2003 without the service pack installed.