How do I check/validate in jQuery whether end date [textbox] is greater than start date [textbox]?
Just expanding off fusions answer. this extension method works using the jQuery validate plugin. It will validate dates and numbers
jQuery.validator.addMethod("greaterThan",
function(value, element, params) {
if (!/Invalid|NaN/.test(new Date(value))) {
return new Date(value) > new Date($(params).val());
}
return isNaN(value) && isNaN($(params).val())
|| (Number(value) > Number($(params).val()));
},'Must be greater than {0}.');
To use it:
$("#EndDate").rules('add', { greaterThan: "#StartDate" });
or
$("form").validate({
rules: {
EndDate: { greaterThan: "#StartDate" }
}
});