Sunday, January 14, 2018

Require a specific data entry pattern in a control

Require a specific data entry pattern in a control

Data validation is the ability to automatically check for errors while the user fills out a form. By adding data validation to controls in your form template, you can ensure that the data that you collect is accurate and consistent, and that it conforms to any standards that are already in use by your company. For example, you can use data validation to let users know when the amount that they enter for an expense item exceeds the approved amount, or when they mistakenly enter their name in a box that is used for collecting phone numbers.

If a form contains data validation errors, and it is connected to a database or Web service, users won't be able to submit the form until they fix these errors. Users can save a local copy of the form, and then correct and submit the data later.

This article explains how to use data validation to help ensure that the data that a user enters into a control matches a predetermined pattern. For example, you can add data validation to a text box control for a phone number to require the user to enter a three-digit area code as part of the number.

Note: 

  • To require that the data that a user enters into a form matches a predetermined pattern, you can also use conditional formatting.

  • When you add a pattern to a control, the control does not automatically reformat the data that a user enters to match the pattern that you set.

In this article

Before you begin

Compatibility considerations

Require a specific data entry pattern in a control

Before you begin

In order to complete this procedure, your form template must contain a control that supports data validation. Although you can set a pattern-matching condition for any InfoPath control that supports data validation, pattern matching works best with controls that display characters, such as numbers, letters, or punctuation. For example, setting a pattern-matching condition for a text box may yield useful results, but setting such a condition for a check box will not yield useful results.

Top of Page

Compatibility considerations

When you design a form template in InfoPath, you can choose a specific compatibility mode to design a browser-compatible form template. When a browser-compatible form template is published to a server running InfoPath Forms Services, and then browser-enabled, forms based on the form template can be viewed in a Web browser. When you design a browser-compatible form template, some controls are unavailable in the Controls task pane because they cannot be displayed in a Web browser.

Some data validation features work differently in a Web browser than they do in InfoPath. For example, when you add data validation to a control, you create explanatory text to be displayed when a user enters invalid data into that control. You can have this explanatory text appear in a ScreenTip, and optionally allow users to display an alert that contains additional information, or you can have the alert appear automatically when a user enters invalid data. Alerts cannot be displayed automatically for forms that are viewed in a Web browser, but users can still view the ScreenTip, and optionally display an alert containing additional information.

List of controls that support data validation

The following table lists the Microsoft Office InfoPath 2007 controls that support data validation and whether they are available for browser-compatible form templates.

Note: Although you can set a pattern-matching condition for any InfoPath control that supports data validation, pattern matching works best with controls that display characters, such as numbers, letters, or punctuation. For example, setting a pattern-matching condition for a text box may yield useful results, but setting such a condition for a check box will not yield useful results.

Controls that support data validation

Available for browser-compatible form templates?

Check box

Yes

Date picker

Yes

Drop-down list box

Yes

List box

Yes

Option button

Yes

Text box

Yes

Rich text box

Yes

Bulleted, numbered, or plain list

No

Combo box

No

Top of Page

Require a specific data entry pattern in a control

  1. Click the control that you want to add data validation to.

  2. On the Format menu, click Data Validation.

  3. In the Data Validation dialog box, click Add.

  4. Under If this condition is true, in the first box, click Select a field or group, and then select the field or group that the control is bound to.

  5. In the second box, click does not match pattern.

  6. In the third box, click Select a pattern.

  7. Under Standard patterns in the Data Entry Pattern dialog box, do one of the following:

    • To use a standard pattern, select the pattern, and then click OK.

      List of standard patterns

      Pattern

      Example

      Phone number

      (555) 555-0100

      Social Security number

      123-45-6789

      ZIP Code

      98052

      ZIP Code + 4

      98052-6399

    • To create a custom pattern, click Custom pattern, type the pattern that you want in the Custom pattern box, and then click OK.

      Symbols you can use to specify a pattern

      You can insert symbols that specify constraints on the pattern, such as letters only, digits only, characters only, hyphens, periods, commas, and parentheses. In addition, you can use the following symbols to allow multiple occurrences of a given character:

      • Zero or one (?)     The preceding character must occur either zero times or one time. For example, \d? means that a digit (signified by \d) must occur either zero times or one time.

      • Zero or more (*)     The preceding character can occur either zero times or more than zero times. For example, r* means that the character r can occur either zero times or more than zero times.

      • One or more (+)    The preceding character must occur either one time or more than one time. For example, .+ means that a character (signified by .) must occur either one time or more than one time.

  8. In the ScreenTip box, type the text that you want to display when a user points to the control or right-clicks the control.

  9. To automatically show a dialog box message when a user leaves a control blank, select the Show dialog box messages immediately when users enter invalid data check box.

    Note: Because dialog box messages cannot be displayed automatically in a Web browser, a user who fills out your form by using a Web browser will see only the ScreenTip.

  10. In the Message box, type the text that you want to display in the dialog box either immediately or when the user requests more details.

    Note: The ScreenTip for a data validation error will not display for controls that also have a default ScreenTip set on the Advanced tab of the Control Properties dialog box. This behavior helps to ensure that the name of the control is accurately conveyed to users who are using screen readers.

Top of Page

No comments:

Post a Comment