I am trying to write a Less than
validator for jQuery.
I want to compare one text box against another, so if I have:
I think you can do that without actually writing your own validator method.
$('#myForm').validate({
rules: {
value1: {
maxlength: $('#value2').val().length
}
}
});
$('#value2').change(function() {
$('#value1').rules('remove', 'maxlength').rules('add', {
maxlength: $('#value2').val().length
});
});
or even better without code duplication
function getRule() {
return {
maxlength: $('#value2').val().length
};
}
$('#myForm').validate({
rules: {
value1: getRule()
}
});
$('#value2').change(function() {
$('#value1').rules('remove', 'maxlength').rules('add', getRule());
});