thank you, it's working fine!
i can't think of a number that does not follow the (XXX) XXX-XXXX because 1
before it is arbitrary
i have a function that will format it that way the minute the the text box
loses focus.. so if the user enters
498 598 9864
229-569-6974
54 654a65s4 a6s54a6s52324
or any combination it will be filtered and tries to create a (XXX) XXX-XXXX
format phone, it works just fine, but i want to do a final check after the
script formats it, because if they don't finish giving all the digits, the
phone number can be wrong.. otherwise it's always correct...
in anycase, this will do just fine for the intranet application i am working
on, once again thank you for all the help!!
"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.29...
Henok Girma wrote on 06 nov 2004 in comp.lang.javascript:
Hello Gurus,
I wanted to have a very simple, strict regular expression validator
for a phone field. the only valid format is
(XXX) XXX-XXXX where X is a digit
I have the following but it always evaluates to false
var reg = new RegExp("^\(\d{3}\) \d{3}-\d{4}$");
alert(reg.test("(123) 221-9244"));
Any help is greatly appreciated..
var reg = /^\(\d{3}\) \d{3}-\d{4}$/;
alert(reg.test("(123) 221-9244"));
However, even(!) in the States there seem to be phone numbers, that cannot
be described in that format.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)