如何验证日期输入是否正确?

时间:2021-05-18

<%
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 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">&nbsp;</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>

[1]

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章