How to validate Phone number Field using Javascript

//phone number validation start
var digits = “0123456789”;
var phoneNumberDelimiters = “()- “;
var validWorldPhoneChars = phoneNumberDelimiters + “+”;
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i);
if (((c < “0”) || (c > “9”))) return false;
}
// All characters are numbers.
return true;
}

function stripCharsInBag(s, bag)
{   var i;
var returnString = “”;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (bag.indexOf(c) == -1) returnString += c;
}
return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function Validatephone(Phone){

if (!checkInternationalPhone(Phone)){
alert(“Please Enter a Valid Phone Number”);
return false;
}
return true;
}

// phone validation ends

About

me : yeay its me arun

Tagged with: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.