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.