Using Validation Operators


Validation operators are used within InfoPath to build criteria that is used to validate data entered on to a form—most of the operators work in a similar fashion to operators you may be familiar with from other applications, including Microsoft Excel. Keep in mind that in addition to using these operators by themselves, you can also combine them with And or Or statements to create complex validation rules.

Performing Comparisons

The most basic type of operators are used for comparison:

  • Is Equal To, Is Not Equal To

  • Is Less Than, Is Less Than or Equal To

  • Is Greater Than, Is Greater Than or Equal To

You are probably familiar with how these comparison operators work—if the comparison is true, then the condition is met and an error message will be displayed. You have seen a couple of these comparison operators in action in the previous example. To use these operators in your own validation rules, right-click the data entry control that you want to work with and select Properties. In the Properties dialog box that opens, click the Data Validation button on the Data tab. In the Data Validation dialog box that opens, click Add to open the blank dialog box shown in Figure 9-6.

click to expand
Figure 9-6: New data validation rule options

Using the leftmost drop-down list provided under If This Condition Is True, select the field or group you want to use for your comparison. By default, this is set to the field that is associated with the data entry control that you are working with, but you can change this to any valid field or group that you are using. Next, use the middle drop-down list to select the operator you want to use in your criteria.

Use the third drop-down list to select a comparison option. The items that appear in this list change depending on the data type of the object that you are working with. For example, if you are working with a text field, you’ll have a number of different options for entering values to use in a comparison. You can type text, a number, a date, and so on, by using the options shown in Figure 9-7.

click to expand
Figure 9-7: Comparison option

On the other hand, if your data entry control is tied to a numeric field, you will only be able to enter a number to be used in your comparison.

start sidebar
How to...—Check for Values

Another neat way to validate user input is to check that they have actually entered some values onto your form. To do this check, you have a special set of operators called Is Blank and Is Not Blank that you can use to check whether some data entry has occurred.

To use these operators, follow the same procedures as outlined previously to create a new validation rule and select this operator from the drop-down list provided. Notice in the illustration that the third (right) drop-down list is unavailable, because this operator isn't used to make a comparison against another entered or selected value—you are only checking whether the data entry object itself has some content.

click to expand

If the user is working with the form and skips a field, the Is Blank operator can be used to let them know, either with an inline message or dialog box, that they have skipped the field.

end sidebar

After you establish your validation rule criteria, you need to select what happens when that criteria is met. By default, validation rules are set to create inline alerts, where the data entry control is underlined in red, indicating that there is an error. Alternately, you could also have InfoPath pop up a dialog box with an error message— it’s up to you. Make your selection from the drop-down list provided and then enter some text for the ScreenTip and message. InfoPath does not allow you to leave the ScreenTip blank, and if you have selected to use a dialog box, you have to enter some text for this as well.

Using Pattern Matching

Pattern matching within validation rules allows you to create patterns that can be used to search through values that are entered into data entry controls. Unlike the comparison operators, such as Equals To, for which you need an exact match, the pattern-matching operators (Contains, Begins With, and so on) can be used to match even part of a value.

There are two different types of pattern-matching operators available—the first is Contains/Does Not Contain, which can be used to search through data that has been entered into a data entry control to find a particular value. For example, if you have a form in which you don’t want users to enter special characters (like an asterisk) in the Company Name field, you could use the Contains operator to trigger an error message when it encounters any of these special characters, as shown in Figure 9-8.

click to expand
Figure 9-8: An example of the Contains operator in use

This operator works regardless of where the special character is within the text. In addition to single characters, you can check for entire phrases (for example, Contains “USA”).

The other pattern-matching operator is Begins With/Does Not Begin With, which is used to compare a value against the beginning characters of a value entered. For example, you could create a validation rule for a Phone Number field such that for all numbers entered starting with 828, an error message would appear reminding the user to check for a changed area code, as in the example shown in Figure 9-9.

click to expand
Figure 9-9: An example of the Begins With operator in use




How to Do Everything with Microsoft Office InfoPath 2003
How to Do Everything with Microsoft Office InfoPath 2003 (How to Do Everything)
ISBN: 0072231270
EAN: 2147483647
Year: 2006
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net