Validate a number between 10 and 11 characters in length
- by Montana Flynn
I am using javascript (and PHP) to validate a simple form with a phone number field. I have it working fine checking that the field has only 10 characters, but I really want to check if the field has between 10 and 11 characters.
Reason being, some people type numbers like so: 1 555 555 5555 and some people do this 555 555 5555.
Here is what I have that works for checking if the length is 10:
if (!(stripped.length == 10)) {
alert("Please enter a valid US phone number.")
return false
}