Comparison of common documents regular Expression verification encyclopedia _ regular expression

Source: Internet
Author: User

Here are some of the more commonly used regular expressions I've collected, because it's usually possible to use more of the form validation. Special sends out, lets each friend use together.

ID Card Verification

JQuery.validator.addMethod ("Isidcard", function (value, element, type) {
 if ($ (type). val () = = ' 1 ') {
 var re =/(^ /d{15}$) | (^/d{18}$) | (^/d{17} (/d| X|X) $)/;
 return this.optional (Element) | | (Re.test (value)); 
 } else {return
  true;
 } 
}, "Incorrect ID card format");

Passport Verification

JQuery.validator.addMethod ("Ispassport", function (value, element, type) {
 if ($ (type). val () = = ' 2 ') {
 var Re1 =/^[a-za-z]{5,17}$/;
 var re2 =/^[a-za-z0-9]{5,17}$/;
 return this.optional (Element) | | (Re2.test (value)) | | Re1.test (value);
 } else {return
 true;
 }
}, "Passport format is not correct");

Hong Kong and Macao Pass verification

JQuery.validator.addMethod ("Ishkmacao", function (value, element, type) {
 if ($ (type). val () = = ' 3 ') {
 var re =/^ [HMHM] {1} ([0-9]{10}| [0-9] {8}) $/;
 return this.optional (Element) | | (Re.test (value));
 } else {return
 true;
 }
}, "Hong Kong and Macao Pass format is not correct");

Taiwan Pass Verification

JQuery.validator.addMethod ("Istaiwan", function (value, element, type) {
 if ($ (type). val () = = "4") {
 var Re1 =/ ^[0-9]{8}$/;
 var re2 =/^[0-9]{10}$/;
 return this.optional (Element) | | (Re1.test (value)) | | (Re2.test (value))
 } else {return
 true;
 }
}, "Taiwan Pass format is not correct");

The above content is small series to introduce more commonly used documents regular expression verification encyclopedia, I hope you like.

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.