Page loading complete initializing form validate
$ ("#user_regForm"). Validate ({errorplacement:function(Error, Element) {if(Element.attr ("id") = = "Province" | | ELEMENT.ATTR ("id") = = "City" | | ELEMENT.ATTR ("id") = = "Area"){ varERROR_TD = Element.parent (). Parent (' DD '). Next (); }Else{ varERROR_TD = element.parent (' DD '). Next (); } error_td.html (""); Error_td.append (Error); Element.addclass ("User_regnok"); }, Error:function(label,element) {Element.addclass ("User_regnok"); }, Success:function(label,element) {Label.addclass (' Reg_validate_right '). Text (' '); Element.removeclass ("User_regnok"); }, Submithandler:function(form) {Console.info ("Submit:" +$ (form). Serializearray ()); Form.submit (); }, OnKeyUp:false, rules: {username:{required:true, Alipay:true, remote: {URL:' Index.php?mod=ajax&act=check_user ', type:' Post ', data:{username:function(){ return$ (' #username '). Val (); }}}, password: {required : true, rangelength:[6,20]}, Password_confirm: {required:true, Equalto:' #password '}, captcha:{required:true, MaxLength:4, remote: {URL:' Index.php?mod=ajax&act=check_captcha ', type:' Post '}}}, messages: {username:{ Alipay:"Enter e-mail or mobile phone number", Remote:"User name already exists"}, Password: {required:' You must provide a password ', Rangelength:' Password length should be between 6-20 characters '}, Password_confirm: {required:' You must confirm your password again ', Equalto:' Two input passwords are inconsistent '}, captcha:{required:"Please enter the verification code", MaxLength:"Enter 4-digit verification Code", Remote:"Captcha Error" } } });
Later, like adding validation rules for some forms
varAdd_user_validate=function() {Console.info ("Add_user_validate"); Remove_user_validate (); $("#province"). Rules ("Add", {required:true, Min:0,messages:{min: "Please select Province"}}); $("#city"). Rules ("Add", {required:true, Min:0,messages:{min: "Please select City"}}); $("#area"). Rules ("Add", {required:true, min:0,messages:{min: "Please select Region"}}); $("#sjhztype"). Rules ("Add", {required:true, min:0,messages:{min: "Please select the type of cooperation"}}); $("#realname"). Rules ("Add", {required:true}); $("#tel"). Rules ("Add", {required:true, mobile:0}); $("#shopname"). Rules ("Add", {required:true}); }
And then for what reason the above elements need to be verified
You can delete a rule
var remove_user_validate=function() { console.info ("remove_user_validate"); $ ("#province"). Rules ("Remove"); $ ("#city"). Rules ("Remove"); $ ("#area"). Rules ("Remove"); $ ("#sjhztype"). Rules ("Remove"); $ ("#realname"). Rules ("Remove"); $ ("#tel"). Rules ("Remove"); $ ("#shopname"). Rules ("Remove");
Ok!!
jquery Validate dynamic Add delete validation rule (reprint)