jquery uses regular expressions to verify phone numbers, mailboxes, ID cards (including Hong Kong, Macao and Taiwan)

Source: Internet
Author: User

Oneself to the regular verification also did not system used, this time to do a demo, all of a sudden put these all use, next time need to take directly.

The following code is used in the page to verify the use of jquery, but also in the background to verify, you can try, all the same principle.

Directly on the code: Note: (Some of the verification rules of course not only this article, perhaps there are other better, can message exchange)

Mobile phone Number: (Mobile-Telecom -Unicom )


var tel = $ ("#PhoneNumber"). Val ();//Get the input phone number

var Yidongreg =/^ (134[012345678]\d{7}|1[34578][012356789]\d{8}) $/;

var dianxinreg =/^1[3578][01379]\d{8}$/;
var liantongreg =/^1[34578][01256]\d{8}$/;
var reg =/^1[3|4|5|7|8]\d{9}$/;//This one can also
if (yidongreg.test (tel) | | dianxinreg.test (TEL) | | liantongreg.test (TEL))

{

}

Mailbox:

var Emailvalue = $ ("#EmailUser"). Val ();//Gets the entered mailbox
var emailreg1 =/^\w+ ([-+.] \w+) *@ ("@") \w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/;//This can also be
var Emailreg =/^\w+ ((-\w+) | ( \.\w+)) *\@ ("@") [A-za-z0-9]+ (\.| -) [a-za-z0-9]+] *\. [a-za-z0-9]+$/;
if (Emailreg.test (Emailvalue))

{

}

Id:

var Usercardvalue = $ ("#UserIDCard"). Val ();//Get Input ID

var Usercardreg =/(^\d{15}$) | (^\d{18}$) | (^\d{17} (\d| X|X) $)/;
var taiwanreg=/^[a-z][0-9]{9}$/;
var xianggangreg=/^[a-z][0-9]{6}\ ([0-9a]\) $/;
var aomenreg=/^[157][0-9]{6}\ ([0-9]\) $/;
if (Usercardreg.test (usercardvalue) | | Taiwanreg.test (usercardvalue) | | Xianggangreg.test (usercardvalue) | | AOMENREG.T EST (usercardvalue))

{

}

There are questions can leave a message, I basically look at once a day. Thank you

jquery uses regular expressions to verify phone numbers, mailboxes, ID cards (including Hong Kong, Macao and Taiwan)

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.