...

View Full Version : Need Form to Validate Phone Number Only



ndwest12
09-06-2011, 03:06 PM
This is what I have so far, it is a template I copied from my working E-mail validation. I'm assuming I have to make it so it's just an array of numbers but I really don't know Java too well.

Essentially I just want numbers only to be accepted into the phone field.



else if(fieldType == 'phone')
{
if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_phone(fieldObj.value)))
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}

}



function validate_phone(phoneStr)
{
apos=phoneStr.indexOf("@");


if (apos<1||dotpos-apos<2)
{
return false;
}
else
{
return true;
}
}

Logic Ali
09-06-2011, 04:29 PM
Searching just within this forum (http://www.google.com/search?q=site%3Awww.codingforums.com+javascript+%2Bphone+number+validation&qfront=javascript+%2Bphone+number+validation&se=on)

jalarie
09-06-2011, 06:25 PM
I wrote a function to check every phone number variation I could find. Just within the North American Numbering Plan, there are over 40 possibilities, and then multiple sub-formats. PM me if you'd like a copy of it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum