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

经常在ASP里面碰到要求用户输入日期,比如生日,那么如何知道他输入的值是否有效呢?比如输入2月,则肯定没有30,31号;又如她要是输入4月,那么肯定没有31号,等等.....
下面是我碰到时的解决方案,在ASP中实现:
Tyear=parseInt(``` =year(date)

 1Tmonth=parseInt(```
 2=month(date)
 3```);   
 4Tday=parseInt(```
 5=day(date)
 6```);   
 7Tdate= Tyear*10000+Tmonth*100+Tday;   
 8Fyear=parseInt(document.register.birthyear.value);   
 9Fmonth=parseInt(document.register.birthmonth.value);   
10Fday=parseInt(document.register.birthday.value);   
11Fdate=(Fyear+18)*10000+Fmonth*100+Fday;   
12  
13if(Fyear==0 || Fmonth==0 || Fday==0){   
14alert("請選擇您的出生日期。");   
15document.register.birthyear.focus();   
16return false;   
17}   
18else if(Fdate>Tdate){   
19alert("對不起,您未滿十八歲。");   
20document.register.birthyear.focus();   
21return false;   
22}   
23else   
24{   
25theDate = new Date(Fyear,Fmonth,0);   
26if (Fday > theDate.getDate ())   
27{   
28window.alert ("出生日期輸入錯誤!");   
29return false;   
30}   
31}
Published At
Categories with Web编程
Tagged with
comments powered by Disqus