Forum Moderators: open

Message Too Old, No Replies

Simple Regex

         

andrewsmd

8:23 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is wrong with this code?
//my phone input
var phone = form[name + ".Applicants.Telephone"].value;

//my regular expression
//it needs to be either 55555555555 or 5555555555
//no - spaces or ()
var phoneReg = /^([0-9]{9}) ¦ ([0-9]{10})$/;
//if the phone does not match
if (!(phone.match(phoneReg))){

msg += ("Please enter a 9 or 10 digit phone number with no dashes or parenthesis.\n");
return false;

} //else if

alert(msg);

I know this code is getting executed because when I comment
everything out and just type alert("test") it does on the form submit. When I uncomment this
I get nothing when I click the submit button meaning something is wrong with my script. I'm not too familiar with regexs anyone got an idea for me. Thanks

andrewsmd

8:36 pm on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nevermind for original testing purposes I was returning false. Well since my alert came after that it was working and returning false. HA it must be friday...

whoisgregg

12:57 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted out, Andrew. :)