jquery Validate dynamic Add delete validation rule (reprint)

Source: Internet
Author: User

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)

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.