to custom validate an input i wrote a script:
function cardNumberCheck(value, element) {
var res = false;
$.get("/CaseHistories/ValidateCardNumber",
{ caseHistoryId: $('#CaseHistory_Id').val(), cardNumber: $('#CaseHistory_CardNumber').val() },
function(data) { res = data });
//alert(res) => works fine return true/false
return res;
}
$.validator.addMethod("cardValidate",
cardNumberCheck, "invalid");
if ($('#CaseHistory_CardNumber').is("form *")) { //<= check if elem is in a form
$('#CaseHistory_CardNumber').rules("add", {
required: true,
cardValidate: true,
messages: {
required: "*",
cardValidate: "invalid"
}
});
}
EDIT:
the required rule works fine, but my validation method doesn't dispalt the message.
and the submit works even if the elements data havent passed the cardNumberCheck validation
whats not right here?