North America Phone Number Validation in Forms
North American Numbering Plan (NANP)
The North American Numbering Plan (NANP) is an integrated telephone numbering plan of 24 countries and territories: the United States and its territories, Canada, Bermuda, and 16 Caribbean nations.
Please Note: Despite the "North American" name of the calling plan, Mexico, the Central American countries and some Caribbean nations are not part of the system.
A phone number in the NANP will start with a three-digit area code which is followed by a seven-digit telephone number that directs telephone calls to particular regions on a public switched telephone network (PSTN), where they are further routed by the local network.
Example of Phone Validation
Cut and Paste Code
Cut 'n' paste code for the above Example
- 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 area code should be started between 2 and 9 and maximum digits should not be greater than 15 digits that it is a valid phone number on form submission