JavaScript Coder

phone number validation

JavaScript Form Validation - Phone Numbers

The easiest way to validate phone numbers using Javascript would be to use Regular expressions. However there are different formats of Phone numbers depending on the user's preference. Here are some regular expressions to validate phone numbers Phone number validation using a simple Regular expression function validatePhoneNumber(input_str) { var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im; return re.test(input_str); } This function will allow phone numbers entered in the formats like this (123) 456-7890 (123)456-7890 123-456-7890 1234567890 Try the working demo See the Pen eYmbjpG by Prasanth (@prasanthmj) on CodePen.

Continue Reading →