This script that allows you to validate a standard 10-digit phone number. Choose whether to
validate using all numbers, -, or spaces.
Script Code
Grab a copy of the file below and place it in the same directory as the Web page on which
you will use the script (if you wish to place the script file in a different directory
you will need to make the necessary adjustments to the src attribute of the script tag
that calls it).
You can choose how the viewer should format the phone number by editing the
num_division variable in the javascript code (instructions in
code comments):
/* Set whether the user should use a -, a space, or one long number without divisions.
Use the following values to set:
1 = Use - (i.e 123-456-7890)
2 = Use a space (i.e. 123 456 7890)
3 = Use none (i.e. 1234567890)
*/
var num_division = 3;
Accessibility
A backup to the script via a server-side script that validates the phone number should
suffice (and is highly recommended for security reasons to avoid bad data being passed).