用Js判断输入的时间是否有效

王朝html/css/js·作者佚名  2006-11-24
宽屏版  字体: |||超大  

经常在ASP里面碰到要求用户输入日期,比如生日,那么如何知道他输入的值是否有效呢?比如输入2月,则肯定没有30,31号;又如她要是输入4月,那么肯定没有31号,等等.....

下面是我碰到时的解决方案,在ASP中实现:

Tyear=parseInt(<%=year(date)%>);

Tmonth=parseInt(<%=month(date)%>);

Tday=parseInt(<%=day(date)%>);

Tdate= Tyear*10000+Tmonth*100+Tday;

Fyear=parseInt(document.register.birthyear.value);

Fmonth=parseInt(document.register.birthmonth.value);

Fday=parseInt(document.register.birthday.value);

Fdate=(Fyear+18)*10000+Fmonth*100+Fday;

if(Fyear==0 || Fmonth==0 || Fday==0){

alert("請選擇您的出生日期。");

document.register.birthyear.focus();

return false;

}

else if(Fdate>Tdate){

alert("對不起,您未滿十八歲。");

document.register.birthyear.focus();

return false;

}

else

{

theDate = new Date(Fyear,Fmonth,0);

if (Fday > theDate.getDate ())

{

window.alert ("出生日期輸入錯誤!");

return false;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有