Validate a number between 10 and 11 characters in length

Posted by Montana Flynn on Stack Overflow See other posts from Stack Overflow or by Montana Flynn
Published on 2010-03-22T18:39:08Z Indexed on 2010/03/22 18:41 UTC
Read the original article Hit count: 288

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
        } 

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about validation