Validate US Telephone Numbers (Freecodemap advanced algorithm 1)

Source: Internet
Author: User

If the incoming string is a valid US phone number, it is returned true .

Users can fill out a form with any valid US phone number. Here are some examples of valid numbers (as well as some variants to use when testing below):

555-555-5555 (555) 555-5555 (555) 555-5555555 555 555555555555551 555 555 5555

In this section you will see strings such as 800-692-7753 or 8oo-six427676;laskdjf . Your task is to verify that the string given above is a valid US phone number. The area code is a must. If the country codes are given in the string, you must verify that they are 1 . Returns if the number is valid true ; Back false .

It needs to be done using regular expressions.

function Telephonecheck (str) {  var reg =/^1?? \d{3}|\ (\d{3}\)) [-]?\d{3}[-]?\d{4}$/;  return Reg.test (str);}
Telephonecheck ("555-555-5555");
(\d{3}|\ (\d{3}\))     --555 or (555) of the form.

Validate US Telephone Numbers (Freecodemap advanced algorithm 1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.