当前位置:编程学习 > asp >>

利用On Error Resume Next来验证日期的输入(ASP 3.0)

答案:刚才又有人问到用javascript来验证日期,回想起自己写了一堆函数来验证日期,而且还没有涉及到闰年的问题,近来看到ASP 3.0关于On Error Resume Next的用法,灵机一动,嘿嘿……。真爽呀!
<%
Option Explicit
Dim strDate            '记录输入的日期,字符型
Dim datDate            '测试输入的日期是否正确,日期型<html>
%>
<head>
<title>日期选择</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href=></head>

<body bgcolor="#FFFFFF" text="#000000">

<Form name="InputDate" ACTION="<% = Request.ServerVariables("SCRIPT_NAME") %>" METHOD="POST">
<table width="500" border="1" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td background="../Pic/br.jpg">
      <table width="500" border="0" cellpadding="4" cellspacing="4" class="9p">
        <tr>
          <td colspan="2"> </td>
        </tr>
        <tr>
          <td colspan="2" height="60">
            <div align="center">请输入所要查询的日期:
              <input type="text" name="strDate" value="<% = Cstr(Year(Now())) & "-" & Cstr(Month(Now())) & "-" & Cstr(Day(Now()))%>" size="10" maxlength="10">
            </div>
          </td>
        </tr>
        <tr>
          <td width="50%">
            <div align="center">
              <input type="submit" name="Submit" value="确 认">
            </div>
          </td>
          <td>
            <div align="center">
              <input type="reset" name="Submit2" value="取 消">
            </div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</Form>
<%
strDate = Request.Form("strDate")
If strDate <> "" Then
    On Error Resume Next
    datDate = CDate(strDate)
    If Err.Number = 0 Then
%>
<Script Language="javascript">
<!--
    InputDate.action="TypeAlert.asp"
    InputDate.submit()
//-->
</Script>
<%
    Else
%>
<Script Language="javascript">
<!--
    alert ("你输入的日期不正确,请重新输入!")
//-->
</Script>
<%
    End If
End If
%>
</body>
</html>

上一个:货币大写转换函数的更新!
下一个:Using the Locale Identifier (LCID) (2)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,