jquery Regular expression verification (mobile number, ID number, Chinese name) _jquery

Source: Internet
Author: User

This article examples need to verify the content: Chinese name, mobile phone number, ID card and address, verification methods to share for everyone to reference, the specific content 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 number:</label>
  <input id= "Phone" type= "text" >
 </div>
 <div class= "Form-group" >
  <label> ID:</label>
  <input id= "Identity" type= "text" >
 </div>
 <div class= "Form-group" >
  <label class= "Label-textarea" > Mailing:</label>
  <textarea "Address" id= textarea>
 </div>
 <p class= "Tip" > Please fill in the real name certification information, so that the acceptance information can not be modified once submitted, please carefully fill out! </p>
 <div class= "Btn-group" >
  <button class= "btn btn-md btn-purple" type= "reset" > Cancel </ button>
  <button class= "btn btn-md btn-purple ml-20" id= "Submit" type= "button" > Submit </button>
 </div>
</form>

jquery Validation:

The

Test () method determines whether the string matches a regular expression content, and returns a Boolean value (True/false)

Verify that the Chinese name function ischinaname (name) {var pattern =/^[\u4e00-\u9fa5]{1,6}$/;
return pattern.test (name); 
 //Verify the mobile number function Isphoneno (phone) {var pattern =/^1[34578]\d{9}$/; 
return pattern.test (phone); //Verify ID function iscardno (card) {var pattern =/(^\d{15}$) | ( ^\d{18}$) | (^\d{17} (\d| 
 X|X) $)/; 
return pattern.test (card);

 }//Verify function Functions Formvalidate () {var str = ';
  The Judgment name if ($.trim (' #name '). Val ()). Length = = 0) {str = ' name not entered \ n ';
 $ (' #name '). focus ();
   else {if (Ischinaname $.trim ($ (' #name '). Val ())) = = False) {str = ' name is illegal \ n ';
  $ (' #name '). focus ();
  }//Judge mobile number if ($.trim (' #phone '). Val ()). Length = = 0) {str = ' mobile number not entered \ n ';
 $ (' #phone '). focus ();
   else {if (Isphoneno $.trim ($ (' #phone '). val ()) = = False) {str = ' cell phone number is incorrect \ n ';
  $ (' #phone '). focus ();
  }//Verify identity card if ($.trim ($ (' #identity '). Val ()). Length = = 0) {str = ' ID number not entered \ n ';
 $ (' #identity '). focus (); else {if (Iscardno ($.trim) ($ (' #identity '). val ()) = = False) {str = ' ID number is incorrect; \ n ';
  $ (' #identity '). focus ();
  }//Verify address if ($.trim (' #address '). Val ()). Length = = 0) {str = ' address not entered \ n ';
 $ (' #address '). focus ();
  ///If no error is submitted if (str!= ') {alert (str);
 return false;
 } else {$ ('. Auth-form '). Submit ();
 } $ (' #submit '). On (' click ', Function () {formvalidate ();});

Hopefully this article will help you learn about the jquery program.

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.