利用On Error Resume Next來驗證日期的輸入(ASP 3.0)

來源:互聯網
上載者:User
error 剛才又有人問到用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="../Css/export.css" type="text/css">
</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>



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.