Validate/Format Phone Numbers
Posted on October 16, 2006
The purpose of this script is to format and validate Telephone Numbers in a form field. The script strips all non-numeric characters and then validates that the remaining characters are sufficient to make up a valid phone number. If there remaining string is 10 characters in length, the script then formats by adding a “-” after the third and sixth digits. Resulting in a mask like ###-###-####.
The example script does the validation/formatting onBlur, meaning when the cursor leaves the Phone Number field. You can also set the event to happen onSubmit or onClick of the Submit button, etc.
View the script in action
Download the script here (< 2kb) Current Download Count: 5677
Filed Under JavaScript |
Leave a Comment
If you would like to make a comment, please fill out the form below.
