Again, I use code to check the string against a regular expression. My expressiong validates that a string contains valid US phone pattern. Ex. (999) 999-9999 or (999)999-9999 or 1234567890
Here's my function that I put in a script object called scoAllScripts:
function validateUSPhone(strValue) {
/************************************************
DESCRIPTION: Validates that a string contains valid
US phone pattern.
Ex. (999) 999-9999 or (999)999-9999 or 1234567890
PARAMETERS:
strValue - String to be tested for validity
RETURNS:
True if valid, otherwise false.
*************************************************/
var objRegExp = /(^\d{10}$)|(^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$)/;
//check for valid us phone with or without space between
//area code
return objRegExp.test(strValue);
}
Here is the code that I put in the Exit event of my phone number field:
if (!this.rawValue == "") {
if(!xfa.form.FSOrder.PAGE1.variables.scoAllScripts.validateUSPhone(this.formattedValue)) {
xfa.host.messageBox("Please enter a telephone number including area code in the format '1234567890' or '(999) 999-9999'");
}
}
Hope that helps.
If you need more help with field validation (i.e, more regular expressions), you can easily find RegExpr pages using a Google search.