gpt4 book ai didi

date - 验证结束日期等于大于开始日期

转载 作者:行者123 更新时间:2023-12-01 01:07:45 27 4
gpt4 key购买 nike

我想用 jquery validate 检查结束日期是否大于或等于开始日期。它正在验证大于开始日期的结束日期,但不允许结束日期等于开始日期,

这是我的代码-

    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"
}
}
});

最佳答案

您应该在自定义方法 greaterThan 中使用 is greater than or equal to(>=)。

改变这一行:

return new Date(value) > new Date($(params).val());

收件人:

return new Date(value) >= new Date($(params).val());

享受...

关于date - 验证结束日期等于大于开始日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15917172/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com