It’d been a while since I’d written JavaScript validation code, but the other day that task got dropped in my lap. Since the phone number inputs were a single text input (which couldn’t really be changed), I decided to go all out and write a fancy schmancy regexp (surprisingly, there weren’t any good ones out there already). Now, it turns out the JS doesn’t really like character classes, but I was able to make do with some sets instead:

/^(?[1-9]d{2}()|.|-)? ?d{3}(.|-| )?d{4}$/

This regexp will allow most combinations of phone numbers – numbers only, area code in parentheses, dashes, or periods. Surprisingly, it worked perfectly in ns4.