我们如何验证两个日期不能超过六个月的日期? [英] how we validate the two dates whose limit cannot exceed more than six months?

查看:84
本文介绍了我们如何验证两个日期不能超过六个月的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有开始日期,我需要提供结束日期,但是我希望当用户在文本字段中输入结束日期时,不允许用户输入结束日期超过六个月的差额,即开始日期和结束日期差额应该六个月.
请用代码向我解释...

假设,

开始日期:-05/11/2011(MM/DD/YY)

输入ENDDATE:2011年11月11日(MM/DD/YY)时,它显示警报月份差值不应超过六".

Suppose i have start date and i need to give end date but i want that when user entering end date in text field it wont allow user to enter end date more than the difference of six month, i.e start date and end date difference should be six months .
please explain me with code...

suppose,

STARTDATE:-05/11/2011(MM/DD/YY)

when entering ENDDATE :-12/11/2011(MM/DD/YY)then it shows alert"months difference should not exceed six"

推荐答案

为什么直接编码? :doh:

进行JavaScript验证,从文本框中获取两个日期.为他们创建日期,例如:
Date startDate = new Date("firstTextboxDate");

找到两个日期之间的差,然后查看是否符合所需范围.

试试!
Why directly code? :doh:

Have a JavaScript validation where you get the two dates out from the textboxes. Create dates for them like:
Date startDate = new Date("firstTextboxDate");

Find the difference of two dates and see if it is as per the range needed or not.

Try!


像这样尝试

Try like this

var date1 = new Date(''05/11/2011'');
var date2 = new Date(''07/11/2011'');
var diff = date2.getTime() - date1.getTime();
diff = diff / (1000 * 60 * 60 * 24 * 30);
if(diff > 6)
     alert(''Not more than 6 months'')


这篇关于我们如何验证两个日期不能超过六个月的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆