Jquery Regular Expression verification: Zip Code address, jquery Regular Expression
Requirement Description:
The front-end page uses regular expressions to verify that the entered data in the text input box is a zip code (the start cannot be 0, 6 digits in total ).
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 options, you can modify them by yourself.
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 = "650000 ";
If (postcode (value )){
Console. log ("parameter: verification required ");
} Else {
Console. log ("parameter: Does not meet verification requirements ");
}
})
// Zip code verification
Function postcode (value)
{
Var reg =/^ [1-9] [0-9] {5} $ /;
Var re = new RegExp (reg );
If (re. test (value ))
{
Return true;
}
Else
{
Return false;
}
}