I’m working with a CMS that includes the ability to build forms, and uses JS validation for those forms. We can replace the existing validation rules with our own Regex if desired.
Currently, the regex in place for Phone Number fields is:
^(1\s*[-/.]?)?(((\d{3}))|(\d{3}))\s*[-/.]?\s*(\d{3})\s*[-/.]?\s*(\d{4})\s*(([xX]|[eE][xX][tT]).?\s*(\d+))*$
This works okay, but we’d also like to exclude numbers that have a 555 for the area code OR exchange. While these are technically numbers that conform to the phone number spec, the decision makers would like them filtered out since they’re usually not “real” numbers.
I’m not enough of a Regex guru to understand how to deal with a “match this, but not that” sort of expression. Can anyone offer any advice/assistance?
Thanks!
You can do a negative lookahead with
(?!555). Put it right after the^(1\s*[-/.]?)?. It w