MVC中的日期选择器验证

3

我有开始日期和结束日期,开始日期应该大于结束日期。

我还有两个日期选择器:折扣开始日期和折扣结束日期。

折扣开始日期应该小于开始日期,折扣结束日期应该小于结束日期。如何使用JavaScript或jQuery编写验证?

1个回答

1

您没有提供日期格式的任何信息,但逻辑始终相同,如下:

var date,endDate,dateDiscount,endDateDiscount;
if ((date<=endDate) || (dateDiscount>=date) || (endDateDiscount>=endDate)) alert('error! dates not good')

解释:

解释:

(date<=endDate) //the reverse of "start date should be greater than end date"
(dateDiscount>=date) //the reverse of "discount start date should be less than start date"
(endDateDiscount>=endDate) // the reverse of "discount end date should be less than end date "

在检查开始日期和结束日期的验证后,我们可以这样编写代码:if ((date<=endDate) { (dateDiscount>=date) || (endDateDiscount>=endDate))} alert('错误!日期不正确') - karthik

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接