Jquery Regular Expression verification: ID card number verification, jquery Regular Expression

Source: Internet
Author: User

Jquery Regular Expression verification: ID card number verification, jquery Regular Expression

Requirement Description:

The front-end page uses regular expressions to verify that the ID card number entered in the text input box complies with the rules.

Code Description:

Here we will only introduce the regular expression section, and the code of other sections will not be introduced. If you have other requirements, modify them.

Step 1: Create a page can be html, jsp, and so on, introduce jquery-3.2.1.min.js (other versions can also ).

Step 2: Write a regular expression.

The Code is as follows:

// Verify the input data when loading the page by default.
$ (Function (){
Var value = "23066619891213C03X ";
If (idcard (value )){
Console. log ("parameter: verification required ");
} Else {
Console. log ("parameter: Does not meet verification requirements ");
}
})

// ID card number verification
Function idcard (value)
{
Var reg =/^ (\ d {15 }$ | ^ \ d {18 }$ | ^ \ d {17} (\ d | X | x) $ /;
Var re = new RegExp (reg );
If (re. test (value ))
{
Return true;
}
Else
{
Return false;
}
}

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.