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

ASP
无限级分类
ASP漏洞全接触-高级篇
ASP漏洞全接触-入门篇
调试ASP脚本
ASP编程经典例子
ASP技术访问WEB数据库
ASP中巧用Response属性
用ISAPIfilter使INC、ASA文件安全
浅析COM的思想及原理(1)
浅析COM的思想及原理(2)
浅析COM的思想及原理(3)
比较ADO与ODBC的区别
asp提供在线文章翻译的功能
关于文摘插件提交表单的开发
Access通用-自动替换数据库中的字符串
复选框用法
1小时ASP入门
显示目录下所有的文件(含文件夹)
[漏洞]利用Activer server explorer可对文件进行读写访问
给你的FSO对象加把锁

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


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