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

ASP
asp中如何限制重复提交同一表单
asp不用DSN访问数据库
ASP文件上传原理分析及实现实例
在ASP程序中访问Access数据库
datagrid编辑、修改、删除、翻页例子
用好ASP.NET 2.0的URL映射
ASP.NET中Datagrid常见错误
ASP.NET 2.0数据缓存功能简介
ASP.NET2.0的缓存控件和地址映射
ASP.NET 2.0中的DataSource系列控件
ASP.NET 2.0中的登陆控件简介
asp存储过程使用
在Asp中使用存储过程
ASP判断文件地址是否有效
ASP+SMTP完成邮件群发功能
用Asp隐藏文件路径实现防盗链
一个通用的保护ASP系统的方法
编写安全的ASP代码
ASP的错误处理集锦
ASP ActiveX 组件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 99 ::
收藏到网摘: 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;
    }
  }