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? Link to comment https://forums.phpfreaks.com/topic/145483-js-regex-problems/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.