JS Authentication number Phone number regular expression

Source: Internet
Author: User
Tags regular expression trim

Some of the following to provide the number of JS verification phone number of the regular expression, is my collection from the Internet, but are fine, professional for mobile phone number and telephone number for verification.

function Checkphone (phone)

{

Verify the phone number of the phone number, including section 153,159

if (phone== "") {

Alert ("Phone number cannot be empty!");

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 has an error. Please use-split ' between area code and telephone number;

return false;

}

}

return true;

}

Mobile phone number Verification

String.prototype.isTel = function ()

{

"Compatible format: Country code 111cn.net (2 to 3 bits)-area code (2 to 3 digits)-Phone number (7 to 8 digits)-ext (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 phone number

String.prototype.isMobile = function () {

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

}

Telephone number Verification

function Checknum () {//Telephone authentication

var Inputvalue=document.gsjbxxbean.dh.value;

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

var isValid

Isvalid=reg.exec (Inputvalue)

if (!isvalid) {

return False

}

return True

}

Check phone number

function Istel (str) {

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

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

return false;

}

else{

return reg.exec (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.