Two methods to verify data in infopath

Source: Internet
Author: User

Turn: http://blogs.msdn.com/infopath/archive/2004/06/16/157315.aspx

Example 1:How do I restrict the user from entering special characters into certain fields in the infopath form?

Note: This example assumes you are running infopath 2003 with the SP-1 feature enhancements enabled. [Added 6/21/04]

The easiest way to do this is to use pattern for data validation. For example, you might wantAUser to enter data in the ########## format for the social security number field. IfTheUser's input does not match this format, youMayWant to throw an alert. You can achieve the above by doing the following:

  1. In design mode, insertTextbox Control
  2. Double click onTextbox ControlTo get the Properties dialog box
  3. Click onData validation | add
  4. Choose"Does not Match Pattern"From the second dropdown and"Select a pattern"From the third dropdown
  5. Click on "Social securityNUmber "from the standard patterns Dialog


  6. Click OK to accept the changes
  7. In the data validation didation, choose "Dialog Box alert" from the error alert type dropdown and specify some alert message


  8. Click OK to accept the changes
  9. You can test your form by clicking onPreview formButton, In the toolbar

Example 2: I cannot put a double quote (") or an apostrophe (') in the pattern builder. How do I validate data against a pattern that contains a double quote (")?

You can validate data against a pattern that contains double quote S by using JScript regular expression. for example, you might want A user to enter data in the "###" format (a pattern contains double quotes) for a field. if user's input does not match this format, you May want to throw an alert. you can achieve the above by doing the following:

    1. In design mode, insertTextbox Control
    2. Double click onTextbox ControlTo get the Properties dialog box
    3. Click onData validation
    4. InScriptSection, choose"Onafterchange"From the dropdown andEdit


    1. Add the followings to your code  

FunctionMsoxd_my_field1: onafterchange (eventobj)

{

// Write code here to restore the global state.

If (eventobj. isundoredo)

{

// An undo or redo operation has occurred and the Dom is read-only.

Return;

}

// A field change has occurred and the Dom is writable. write code here to respond to the changes

// Specify your pattern using JScript Regular Expression

VaRRE1 =NewRegexp ("" x22 "" D "x22 ");

// Get the field value

VaRS = xdocument. Dom. selectsinglenode ("My: myfields/My: field1"). text;

// Find a match within string s

If (re1.exe C (S) =Null& Eventobj. Operation = "Insert ")

Xdocument. UI. Alert ("user input does not match the required pattern ");

}

 

    1. After editing all the code, click OK to accept the changes
    2. You can test your form by clicking onPreview formButton, In the toolbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.