我想检查结束日期是否大于或等于开始日期,使用 jquery 验证。它正在验证结束日期大于开始日期,但不允许结束日期等于开始日期,
这是我的代码 -
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}.');
jQuery("#collect_and_delivery").validate({
errorElement:'div',
rules: {
from:{
required:true
},
to:{
required:true
},
start_date:{
required:true
},
end_date:{
required:true,
greaterThan: "#start_date"
}
},
messages: {
from:"Please enter collect address",
to:"Please enter delivery address",
start_date:"Please enter shipping collect date",
end_date:
{
required:"Please enter shipping delivery date",
greaterThan:"Delivery date and Collect date should be proper"
}
}
});