//verification of real name authentication$(function(){ //Chinese name VerificationJQuery.validator.addMethod ("Zh_verify",function(value, Element) {varTel =/^[\u4e00-\u9fa5\uf900-\ufa2d]{2,10}$/; return This. Optional (Element) | |(Tel.test (value)); }, "Please input 2~10 words in Chinese!" "); //Identification Number VerificationJQuery.validator.addMethod ("Idcard_verify",function(value, Element) {varIdcard =/^ (\d{15}$|^\d{18}$|^\d{17} (\d| x|x)) $/; return This. Optional (Element) | |(Idcard.test (value)); }, "Please enter the correct format of the ID number!" "); //Jquery.validate plug-in verification$ ("#nameauth"). Validate ({errorelement:' Div ', Errorclass:' Help-block ', Focusinvalid:false, ignore:"", rules: {tname: {required:true, Zh_verify:true}, Idcard: {required:true, Idcard_verify:true}, Con_idcard: {required:true, Equalto:'. Idcard '}}, messages: {tname: {required:"The real name can't be empty!" ", Rangelength:"Please input 2~18 Chinese!" "}, Idcard: {required:"ID can't be empty!" ", Rangelength:"Please enter a 15~18 character ID!" "}, Con_idcard: {required:"The confirmation number cannot be empty!" ", Equalto:' The confirmation number and the ID number are inconsistent! ‘}}, Errorlabelcontainer:"#resultMsg", Submithandler:function() { //$ (form). Ajaxsubmit (); To submit a form synchronously varTname = $ (' input[name=tname] '). Val (); varIdcard = $ (' input[name=idcard] '). Val (); varresultmsg = $ (' #resultMsg '); Ajaxsubmitform (Tname, Idcard, resultmsg); } });})//Asynchronous execution MethodsfunctionAjaxsubmitform (Tname, Idcard, resultmsg) {$.ajax ({URL:"/member/nameauth", Data:"Tname=" + tname + "&idcard=" + Idcard + "&con_idcard=" +Idcard, type:"POST", Cache:false, DataType:"JSON", Success:function(data, textstatus) {if(Data.return) {window.location.reload (); }Else{resultmsg.css ({' Color ': ' Red '}. html (DATA.ERRMSG). Show (). Delay (0); } } });}
Or
$(function(){ //jquery.validate plug-in Custom Ajax authentication (verify that the account exists)$.validator.addmethod ("Checkuserexist",function(value,element) {varuser =value; $.ajax ({type:"POST", Async:true, DataType:' JSON ', URL:"/account/verifyaccount", Data:"Param=" + $ (' Input[name=newpassword] '). Val (), Success:function(response) {if(response) {res=response.state; } } }); returnRes; },"The account does not exist, please check carefully!" "); //Jquery.validate plug-in verification$ ("#signupForm"). Validate ({rules: {newpassword : {required:true, rangelength:[6,30]}}, messages: {newpassword: {required:"Please enter the trading password of 6~30 characters!" ", Rangelength:"Please enter the trading password of 6~30 characters!" "}}, Submithandler:function(Form) {$ (form). Ajaxsubmit (); } });})
JqueryValidate Tutorials
Http://www.w3cschool.cc/jquery/jquery-plugin-validate.html
The method and tutorial of JQuery Validate verification