Stop Validating Phone Numbers

Ah, the siren song of the phone number field validator…

Spolsky tweet

Can you imagine if you asked someone to write down their phone number for you, and then told them: Sorry, you forgot to surround the area code with parentheses. TRY AGAIN.

Oh, whoops, your phone number has to start with a 1. TRY AGAIN.

The great thing about human beings is that they can deal with ambiguity, while computers are classically ambiguity-intolerant. Unless your software needs to programmatically call the phone number, then why does it need to be in some exact format?

Certain kinds of validations just aren’t worth it, as they do more harm than good. As developers, our job is to help the user, not get in their way.


I can hear developers everywhere screaming: What if they fat-finger the number, typing a ‘w’ when they meant to type a ‘2’!? We must protect them from themselves! Is that any more likely than the user typing a ‘3’ when they meant to type a ‘2’? How is your regex going to catch that?

The point is just to be aware that sometimes resisting the urge to validate is the right thing to do for the user. Think twice before you reach for that regex!