JQuery Validate Implementation Dynamic Add / Delete Verification Rule Operation Example

The instance of this article describes the JQuery Validate implementation dynamically increase / delete verification rule operation. Share to everyone for your reference, specifically:

Page loading completion initialization Form Validate

  $ ("# user_regform"). Validate ({ErrorPlace: Function (ERROR, ELEMENT) {if (Element.attr ("ID") == "province" || Element.attr ("ID") == "City" || Element.attr ("ID") == " Area ") {var error_td = element.parent (). Parent ('DD'). Next ();} else {var error_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");}, SUBMITHANDAL: FUNCTION (FORM) {Console.info ("Submit:" + $ (Form); form.submit ()); form.submit ();}, onkeyup: false, rules: {usrname: {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 an email or mobile number", Remote: "User Name already exists"}, password: {required:' You must provide a password ', Rangelength:' The password length should be between 6-20 characters'}, password_confirm: {required: 'You must confirm your password', Equalto: 'Two input passwords are inconsistent with'}, captcha: {Required : "Please enter the verification code", maxlength: "Enter 4-bit verification code", Remote: "Verification code error"}}});  

After later, such as an increase in Validation rules

 VAR add_user_validate = function () {console.info ("add_user_validate"); transove_user_validate (); $ ("# provvice"). Rules "add", {required: true, min: 0, message: {min: "Please select the province"}}); $ ("# City"). Rules ("add", {Required: True, Min: 0, Messages: {MIN: "Please select the city"}}); $ ("# aa"). Rules ("add", {required: true, min: 0, Messages: { MIN: "Please select Zone"}}); $ ("# SJHzType"). Rules ("add", {required: true, min: 0, message: {min: "Please select the collaboration type"}}); $ ("#realname"). Rules ("add", {required: true}); $ ("# tel"). Rules ("add", {required: true, mobile: 0}); $ ("# ShopName ") .Rules (" add ", {required: true});}   
later, because of why unknown elements need to be verified

can be deleted Rules

VAR Remove_user_validate = function () {Console.info (“Remove_user_validate”); $ (“# provvice”). Rules (“remove”); $ (” #city “). Rules (” remove “); $ (” # area “). Rules (” REMOVE “); $ (” # SJHzType “). Rules (” Remove “); $ (” # realname). Rules (“Remove”); $ (“# tel”). Rules (“REMOVE”); $ (“# ShopName”). Rules (“remove”);}
  " OK! ! 
More about jQuery related content, readers can be viewed on this site: “jQuery page element operation skills summary”, “jQuery common event usage and skill summary”, “jQuery common plug-in and usage summary”, “JQuery extension skill summary” and “JQuery Selector Summary”

I hope this article will help you jQuery program.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment