I have a form which have three fields
- Old Password
- New Password
- Confirm Password
These fields are optional and only mandatory when user enter some text into New Password How can i apply jQuery Validator plugin for the same.
jQuery.validator.addMethod("pass2",
function(value,element,param) {
var op=document.forms[0].oldpass;
var newp=document.forms[0].newpass1;
var cp=document.forms[0].newpass2;
if(newp.value != "" )
{ if(element.name=="newpass2")
{ if(cp.value!=newp.value) {return true;}
else {return false;}
}
if(element.name=="oldpass")
{ if(op.value=="") {return true;}
else { return false;}
}
}
else
return true;
},"");
$(document).ready(function() {
$("#form1").validate({
debug:true,
rules: {
oldpass:
{
pass2:true
},
/*newpass1:
{
pass1:true
},*/
newpass2: {
pass2:true
}
},
messages: {
oldpass: "Please enter a oldpass",
//newpass1: "Please enter newpassword",
newpass2: "Please confirm password"
}
});
});
">