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;
}
}