Expand my Community achievements bar.

How do you ensure that what I typed in the Phone number must be an 8 digit number?

Avatar

Former Community Member
Hi all,



I am now creating a text box that allows a person to type in an 8 digit phone number according to my country's specifications. If a person types in a single digit, how do I have a validation check to ensure that he has to type in 8 digits? Under Validation Pattern, I typed in 99999999 but the person can still type in a single digit and still pass through! It will only validate when a person types in more than 8 digits.



What gives?



Thanks for reading!
2 Replies

Avatar

Former Community Member
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.

Avatar

Former Community Member
Hi SGreen,



Thanks for your prompt reply. Am I right to Insert the Script Object to my subform and rename the script object as scoAllScripts? Its like a container where it contains all the functions right?



Sorry, what I don't understand is the regular expression. Is it some kind of Javascript? If I want the person to type in only 8 characters, must I type in so many wildcards?



Another problem I am facing is that I need to enter the validateUSPhone calling function within the exit event. May I know is it FormCalc or Javascript as my client-side language? Because either way, I still do not get the validation check.



Thanks for reading!