Js verification phone number, mobile phone number, Regular Expression

Source: Internet
Author: User

The following are some regular expressions for js verification phone numbers. I have collected them from the Internet, but they are all excellent products. They are specialized in mobile phone numbers and phone numbers.

Function checkPhone (phone)

{

// Verify the phone number, including the phone number 153,159

If (phone = ""){

Alert ("the phone number cannot be blank! ");

Return false;

}

If (phone! = ""){

Var p1 =/^ ([0 +] d {2, 3 }-)? (0d {2, 3 })-)? (D {7, 8}) (-(d {3 ,}))? $ /;

Var me = false;

If (p1.test (phone) me = true;

If (! Me ){

// Alert ('Sorry, www.45it.com the phone number you entered is incorrect. Use-to separate the area code from the phone number ');

Return false;

}

}

Return true;

}

Mobile phone number verification

String. prototype. isTel = function ()

{

// "Compatible format: Country Code bKjia. c0m (2 to 3 digits)-area code (2 to 3 digits)-telephone number (7 to 8 digits)-extension number (3 digits )"

// Return (/^ ([0 +] d {2, 3 }-)? (0d {2, 3 })-)? (D {7, 8}) (-(d {3 ,}))? $/. Test (this. Trim ()));

Return (/^ ([0 +] d {2, 3 }-)? (0d {2, 3})-) (d {7, 8}) (-(d {3 ,}))? $/. Test (this. Trim ()));

}

// Verify the mobile phone number

String. prototype. isMobile = function (){

Return (/^ (? : 13d | 15 [89])-? D {5} (d {3} | * {3}) $/. test (this. Trim ()));

}

Phone number verification

Function CheckNum () {// phone Verification

Var InputValue = document. gsjbxxBean. dh. value;

Var reg =/^ ([0-9] | [-]) + $/g;

Var isValid

Isvalid1_reg.exe c (InputValue)

If (! IsValid ){

Return false

}

Return true

}

Check the phone number

Function isTel (str ){

Var reg =/^ ([0-9] [-]) + $/g;

If (str. length <7 str. length> 18 ){

Return false;

}

Else {

Return reg.exe c (str );

}

}

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.