当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用Js判断输入的时间是否有效

ASP
ASP 中 Split 函数的实例
存贮过程
asp内置对象 ObjectContext详解
如何写出优秀的ASP应用
用ASP制作强大的搜索引擎
ASP 系列函数大全
彩色校验码的制作
ASP中使用SQL语句教程
ASP提速技巧五则
ASP进度条
在电子商务中实现购物车的方法
ASP读取系统时区的错误行为修正
Rs.open sql,conn,A,B 的A、B各代表什么?
FSO组件操作实例技巧
用asp连接各种数据库的方法
WEB打印设置解决方案一
WEB打印设置解决方案二
WEB打印设置解决方案三
实例分析CSS属性Display与Visibility不同
每页都有的表头和打印分页

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 42 ::
收藏到网摘: n/a

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