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 want a user to enter data in the ###-##-#### format for the Social Security Number field. If the user’s input does not match this format, you may want to throw an alert. You can achieve the above by doing the following:
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 quotes 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:
// Write code here to restore the global state.
// An undo or redo operation has occurred and the DOM is read-only.
// 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
var re1 = new RegExp(“\x22\\d\\d\\d\x22”);
// Get the field value
var s = XDocument.DOM.selectSingleNode(“my:myFields/my:field1”).text;
// Find a match within string s
if (re1.exec(s) = = null && eventObj.Operation = = “Insert”)
XDocument.UI.Alert(“User input does not match the required pattern”);
PingBack from http://www.keyongtech.com/2008008-infopath-2007-pattern-matching-custom