Jquery Regular Expression (mobile phone number, ID card number, Chinese name), jquery Regular Expression

Source: Internet
Author: User

Jquery Regular Expression (mobile phone number, ID card number, Chinese name), jquery Regular Expression

Content to be verified in this example: Chinese name, mobile phone number, ID card and address. The verification method is shared with you for your reference. The details are as follows:

HTML (form ):

<Form action = ""> <div class = "form-group"> <label> Name: </label> <input id = "name" type = "text"> </div> <div class = "form-group"> <label> mobile phone number: </label> <input id = "phone" type = "text"> </div> <div class = "form-group"> <label> id card: </label> <input id = "identity" type = "text"> </div> <div class = "form-group"> <label class = "label-textarea"> Mailing address: </label> <textarea id = "address"> </textarea> </div> <p class = "tip"> enter the real-name authentication letter. Information, so that once the prize receipt information is submitted, it cannot be modified. Please enter it with caution! </P> <div class = "btn-group"> <button class = "btn-md btn-purple" type = "reset"> cancel </button> <button class = "btn-md btn-purple ml-20" id = "submit" type = "button"> submit </button> </div> </form>

JQuery Verification:

The test () method is used to determine whether the regular expression content is matched in the string. the return value is a boolean value (true/false)

// Verify the Chinese name function isChinaName (name) {var pattern =/^ [\ u4E00-\ u9FA5] {} $/; return pattern. test (name) ;}// verify the mobile phone number function isPhoneNo (phone) {var pattern =/^ 1 [34578] \ d {9 }$/; return pattern. test (phone) ;}// verify the ID card function isCardNo (card) {var pattern =/(^ \ d {15} $) | (^ \ d {18} $) | (^ \ d {17} (\ d | X | x) $)/; return pattern. test (card) ;}// verify the function formValidate () {var str = ''; // judge the name if ($. trim ($ ('# name '). Val ()). length = 0) {str + = 'name is not input \ n'; $ ('# name '). focus ();} else {if (isChinaName ($. trim ($ ('# name '). val () = false) {str + = 'invalid name \ n'; $ ('# name '). focus () ;}/// determine the mobile phone number if ($. trim ($ ('# phone '). val ()). length = 0) {str + = 'mobile phone no. \ n'; $ ('# phone '). focus ();} else {if (isPhoneNo ($. trim ($ ('# phone '). val () = false) {str + = 'incorrect mobile phone number \ n'; $ ('# phone '). focus () ;}// verify the ID card if ($. trim ($ ('# identity '). Val ()). length = 0) {str + = 'id card number is not entered \ n'; $ ('# identity '). focus ();} else {if (isCardNo ($. trim ($ ('# identity '). val () = false) {str + = 'incorrect ID card number; \ n'; $ ('# identity '). focus () ;}// verify the address if ($. trim ($ ('# address '). val ()). length = 0) {str + = 'the address is not input \ n'; $ (' # address '). focus ();} // submit if (str! = '') {Alert (str); return false;} else {$ ('. auth-form '). submit () ;}$ ('# submit '). on ('click', function () {formValidate ();});

I hope this article will help you learn jquery programming.

Articles you may be interested in:
  • Regular Expression Analysis in jQuery
  • Regular Expression description in jquery
  • JQuery source code analysis-02 Regular Expression RegExp common Regular Expression
  • Regular Expression sorting for JQuery numeric type verification
  • Jquery Validate Regular Expression Practical Verification Code
  • Summary of regular expressions used to verify the time format in jQuery
  • Jquery uses regular expressions to verify the email address
  • JQuery obtains the regular expression of the name of the uploaded file.

Related Article

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.