The jsFiddle: http://jsfiddle.net/hbrls/Snn87/12/
I have a verify code field: <input type="text" id="verfy_code" name="verfy_code" class="required" />
and the validation js is:
$("#aspnetForm").validate({
rules: {
verfy_code: {
required: function(element) { return check_verfy_code(); }
}
},
messages: {
verfy_code: { required: "verify code not correct" }
}
});
function check_verfy_code() {
var flag = false;
//some ajax to check if verfy_code equalto session["verfy_code"]
//I've not implemented this, so this function will always return false
return flag;
}
The messages never show.
Check the documentation for the
required(dependency-callback)option:You are always returning
false, therefore the element is never required.If you return
truefrom your function your dependency callback will work as you expect:Example: http://jsfiddle.net/jZjFq/