JQuery uses regular expressions to verify mobile phone numbers, email addresses, ID cards (including Hong Kong, Macao and Taiwan(China)), and jquery Regular Expressions

Source: Internet
Author: User

JQuery uses regular expressions to verify mobile phone numbers, email addresses, ID cards (including Hong Kong, Macao and Taiwan(China)), and jquery Regular Expressions

I have never used the regular expression verification system. I made a demo this time and used it all at once. I will take it directly next time.

The following code uses JQuery for verification on the page, and is also used for verification in the background. You can try the same principle.

Directly run the Code:Note: (some verification rules are not only in this article, but may also be better. You can leave a message)

Mobile phone number: (mobile-Telecom-China Unicom)


Var tel = $ ("# PhoneNumber"). val (); // obtain the entered mobile phone number

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

Var dianxinreg =/^ 1 [3578] [01379] \ d {8} $ /;
Var liw.greg =/^ 1 [34578] [01256] \ d {8} $ /;
// Var reg =/^ 1 [3 | 4 | 5 | 7 | 8] \ d {9} $ /; //
If (yidongreg. test (tel) | dianxinreg. test (tel) | liw.greg. test (tel ))

{

}

Email:

Var emailvalue = $ ("# EmailUser"). val (); // obtain the input email address
// 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 card:

Var userCardvalue = $ ("# UserIDCard"). val (); // get the input ID card

Var userCardreg =/(^ \ d {15} $) | (^ \ d {18} $) | (^ \ d {17} (\ d | X | x) $ )/;
Var xianggangreg =/^ [A-Z] [0-9] {6} \ ([0-9A] \) $ /;
Var aomenreg =/^ [157] [0-9] {6} \ ([0-9] \) $ /;
If (userCardreg. test (userCardvalue) | test (userCardvalue) | xianggangreg. test (userCardvalue) | aomenreg. t est (userCardvalue ))

{

}

If you have any questions, you can leave a message. I usually view the message once a day. Thank you.

 


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.