toggle menu

How to write validation rules inside jquery validate() and jquery valid() function

Ravinder |21 Jun at 11:06

Complete Solution here:

The main difference between validate() and valid()

Jquery validate() is execute on form submit with submit button while

jquery valid() is execute on click button event, this is very usefull to validate field  in modal box and validate the field without submit form 

 

add rules in jquery validate() method

 

$(document).ready(function(){

$("#formid").validate({//form id 

rules: {

emailid: {/field name

required: true,

email: true

}

}

});

});

 

add rules in jquery valid() method

$(document).ready(function(){

var form = $( "#forgotpwdfrm" );//form id 

form.validate({//define rules 

rules: {

uname: {//field name uname

required: true,

minlength: 8

},

mobile: {//field name mobile

required: true,

}

}

});

$('#forgotpwd').click(function(){//on click event

alert( "Valid: " + form.valid() );//you can write your logic here 

 

});

});

 

  • 1 like
  • 0 comment

Posted:

21 Jun at 11:06

Viewed:

1295 times

Active:

26 Jun at 01:06