Javascript Tutorials

RegEx Phone Number Validation

Javascript Phone Number Validation Using Reqular Expression

Phone Number Validation using Regular Expression

In forms when asking for phone numbers fields it is a good idea to use client side validation along with your programming language validation. The following example shows how you can do this.

We have also provided the javascript phone validation for the Internationl Phone number validation, U.S. number and specially for North America Phone number validation.


Example of phone validation

Enter a Phone Number :

Cut and Paste Code

Cut 'n' paste code for the above Example

JavaScript Code


Explanation of the Code

The JavaScript has the following main functions:

  • Function checkInternationalPhone is used to verify if the given value is a possible valid international phone number : This function first removes all non-digit characters which are allowed in phone numbers. These delimiters are declared in the lines (found in the beginning of the code) :

    var phoneNumberDelimiters = "()- "
    var validWorldPhoneChars = phoneNumberDelimiters + "+"

    Now that all valid delimiters are removed we just check if the remaining value is an integer and that it has at least a certain number of digits (given by the variable 'minDigitsInIPhoneNumber').

  • Function ValidateForm is used to make sure that the phone number field is not blank and that it is a valid phone number on form submission
Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!