unkwntech Posted February 16, 2009 Share Posted February 16, 2009 I have this code to check a form field that should contain a phone number, however when I run the function that this is in I get the following on the console: Chrome: Uncaught SyntaxError: Invalid regular expression: //(?[0-9]{3})?[ -]?[0-9]{3}[ -]?[0-9]{4}/i/: unrecognized character after (? FireFox: Error: invalid quantifier ?[0-9]{3})?[ -]?[0-9]{3}[ -]?[0-9]{4}/i if(!ph.value.match('/\(?[0-9]{3}\)?[ -]?[0-9]{3}[ -]?[0-9]{4}/i')) { console.log('Phone Number is not valid'); ph.className = 'errorOnField'; } RegEx buddy says that this RegEx is valid for JS but obviously there is a problem, what am I doing wrong? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.