JavaScript Test For Valid US Phone Number

TLDR;

Example and script at http://sandbox.michaelgrace.org/phone-number-validation/

In building an app, I needed to check for a valid phone number based on user input. After reading and learning more about US phone numbers than I cared about, I was able to come up with a basic way to check for a valid US phone number using JavaScript. It only marks a phone number as invalid if it is a phone number that is not a possible phone number or a special phone number that customers will not have (800 numbers, etc.).

I built a US phone number validation test page that will test phone numbers you input and give the reason why it fails if it doesn’t pass validation. You can check it out at http://sandbox.michaelgrace.org/phone-number-validation/

Resources I ended up using in my research or the formulation of the algorithm:

 

Photo by Paul L

Published by

MikeGrace

I am a Geek! I hope you enjoyed this recent post.