欢迎光临
我们一直在努力

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

建站超值云服务器,限时71元/月

  经常在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;
  }
}

 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 用Js判断输入的时间是否有效.
分享到: 更多 (0)

相关推荐

  • 暂无文章