I have been struggling with a javascript regex validation for U.S. phone numbers all afternoon. This is part of Manuel Lemos' Formsgen class. This is limited to the 7 digit number sans 3 digit area code. To be complete, the regex should disallow a phone number that begins with 0 or 1, 555 or any digit followed by 11. Here is the regex I'm using:

^(?!\d[1]{2}|[5]{3})([2-9]\d{2})([-])\d{4}$

Manual Lemos indicated to me in an offline post that this should throw a javascript runtime error because of the (? at the beginning of the regex. I have tested it in over a dozen different browsers (Windows and Mac) and the only one that throws the runtime error is IE on the Mac. All others catch the errors I am trying to trap for with no runtime errors. Can this regex be improved on or do I have to live with the idiosyncratic behavior of Mac IE?

Thanks.

Albert Padley

Reply via email to