Jquery Regular Expression verification: Zip Code address, jquery Regular Expression

Source: Internet
Author: User

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

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.