检查javascript的验证 [英] checking the validation for javascript
本文介绍了检查javascript的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
请查看以下javascript:
Dear All,
Please take a look at the following javascript:
function validate()
{
if(!checkDate( document.form1.txtFdate.value ) )
{
alert("Invalid Date");
document.getElementById("txtFdate").focus();
return false;
}
if(!checkDate( document.form1.txtTdate.value ) )
{
alert("Invalid Date");
document.getElementById("txtTdate").focus();
return false;
}
var dateString=document.form1.txtFdate.value;
var Fdate = (dateString.substring(6,10))+(dateString.substring(3,5))+(dateString.substring(0,2));
dateString=document.form1.txtTdate.value;
var Tdate = (dateString.substring(6,10))+(dateString.substring(3,5))+(dateString.substring(0,2));
if(parseInt(Tdate,10)<parseInt(Fdate,10))
{
alert("To Date Cannot Be Less Than From Date");
document.getElementById("txtTdate").focus();
return false;
}
if((parseInt(Tdate,10)-parseInt(Fdate,10))>6)
{
alert("Difference Between From and To Date Cannot Be More than 6 Days");
document.getElementById("txtTdate").focus();
return false;
}
}
在这里,它适用于每个月,但如果我选择从3月31日到4月1日,它会显示相同的消息,即从日期到日期之间的差异不能超过6天".
这可能是什么问题?请帮助我.....
Here Its working fine for the Individual month, but if I select 31st march to 1st April, it gives the same message saying "Difference Between From and To Date Cannot Be More than 6 Days".
What might be the problem in this? please help me.....
推荐答案
try:
var Fdate =(dateString.substring(7,10))+(dateString.substring(3,4))+(dateString.substring(0,1));
与Tdate相同...
try :
var Fdate = (dateString.substring(7,10))+(dateString.substring(3,4))+(dateString.substring(0,1));
the same for Tdate ...
用于进行日期比较的精确方法是在比较之前将日期转换为毫秒/秒(时间戳).这是另一种建议
The precise method for date comparison would be convert the date to milliseconds/ seconds (timestamp) before comparing. It is an alternative suggestion
这篇关于检查javascript的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文