Javascript validating phone number field

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.

By starting your regex with '^' and not ending it with '$', you match lines that start with a sequence matching your regex, but lines can have anything else trailing the matching sequence.

This is repeated between the second and third grouping of numbers, and we check for 3 consecutive digits then four consecutive digits to end it.

Now below is our j Query code: On submitting the form, the j Query first checks if the phone input field has the value with number and length is between 10. Live word counter from HTML textarea in Java Script Now let’s test it on your browser.

The Java Script is Na N method is used to check if the input data contains the only number. You will see if any of the characters in the phone field is not a number or is less than 10 in length or greater than 10 in length, the form will not be submitted.

If you want to match at word boundaries, just change the ^ and $ to \b I welcome any suggestions, corrections, or criticisms of this solution.

I write this code by myself and I think this is very good way to use in input. It will help user to correct their format on input tag. (902-455-4555 will not work since there is no closing parenthesis.

This will validate all US style numbers, with or without the 1, and with or without parenthesis on area code(but if used, used properly. it also allows for either - or a space between sets if wanted.) It will work for the examples provided by op.

because your regular expression does match the input.

It's just that the input also includes the extra characters.

Search for javascript validating phone number field:

javascript validating phone number field-88javascript validating phone number field-18

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “javascript validating phone number field”

  1. This free streaming cam is located at the All Claddagh shop, located between the famous Ha’Penny Bridge and the O’Connell Bridge in the centre of Ireland’s Capital city, Dublin.