Validation:
Chinese name, cell phone number, ID card and address
HTML (form):
<formaction=""> <Divclass="Form-group"> <label> Name: </label> <inputId="Name"Type="Text"> </Div> <Divclass="Form-group"> <label> Mobile Number: </label> <inputId="Phone"Type="Text"> </Div> <Divclass="Form-group"> <label> ID: </label> <inputId="Identity"Type="Text"> </Div> <Divclass="Form-group"> <labelclass="Label-textarea"> Mailing Address: </label> <textareaId="Address"></textarea> </Div> <Pclass="Tip"> Please fill in the real name authentication information, so that the acceptance information can not be modified once submitted, please carefully fill out. </P> <Divclass="Btn-group"> <Buttonclass="btn btn-md btn-purple"Type="Reset"> Cancel </Button> <Buttonclass="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 the contents of the regular expression, 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 ();});
I used in the project, thank you for your attention ~