At the very least it should be var m = value.match(/\d/g); return m && m.length === 10This led me in the right direction. Unfortunately this expression will also match (1234567890 and 123)4567890. If you want to match at word boundaries, just change the ^ and $ to \b I welcome any suggestions, corrections, or criticisms of this solution.
The option of using pure HTML, sometimes with a touch of CSS, to complement Java Script form validation was until recently unthinkable.
Click here for NANP phone number validation and US only phone number validation.
Date Validation Email Validation Phone Number Validation U.
Form Validation provides the built-in phone validator to validate the phone number in various countries.
I'm using this regular expression, First off, your format validator is obviously only appropriate for NANP (country code 1) numbers.
Will your application be used by someone with a phone number from outside North America? Finally, I get the feeling you're validating user input in a web browser.
Also each browser has a slightly different default behaviour.
The simplest change you can make to your forms is to mark a text input field as 'required': This informs the (HTML5-aware) web browser that the field is to be considered mandatory.
The validating phone number is an important point while validating an HTML form.
In this page we have discussed how to validate a phone number (in different format) using Java Script : At first, we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no sign in front the number.
(\d)$/ the first part of the older regex didn't do well: "(()?