CoffeeQuick
Programmer
Hi,
I came across this script the other day for validating phone/fax numbers, it's about the best one i've seen, although it had a few bugs in it, which i've ironed out (exp originally came up with a syntax error, it had () where the shouldn't have been, and didn't like properly formated London numbers eg 020 8231 9331).
It allows for international numbers and for extension numbers added at the end.
So I thought I would share it with you.
Here's the code.
Hope this is of use to someone.
John![[atom] [atom] [atom]](/data/assets/smilies/atom.gif)
I came across this script the other day for validating phone/fax numbers, it's about the best one i've seen, although it had a few bugs in it, which i've ironed out (exp originally came up with a syntax error, it had () where the shouldn't have been, and didn't like properly formated London numbers eg 020 8231 9331).
It allows for international numbers and for extension numbers added at the end.
So I thought I would share it with you.
Here's the code.
Code:
function validPhoneNumber(formField)
{
var phone = formField.value;
var exp = /^(\+\d{1,3} ?)?(\(\d{1,5}\)|\d{1,5}) ?\d{3,4} ?\d{0,7} ?(x|xtn|ext|extn|extension)??\.? ?\d{1,5}?$/i;
var isValid = exp.test(phone);
if (!isValid) {
alert("Please enter valid telephone number");
formField.focus();
}
return isValid;
}
Hope this is of use to someone.
John
![[atom] [atom] [atom]](/data/assets/smilies/atom.gif)