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

时间:2010-06-10 18:38:00 

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

我们可以利用ASP 3.0里的On Error Resume Next来完成这项功能:

<%
Option Explicit
Dim strDate            
' 记录输入的日期,字符型
Dim datDate            
' 测试输入的日期是否正确,日期型
<html>
%>
<head>
<title>日期验证 - asp之家</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">&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>

标签:验证,日期,asp
0
投稿

猜你喜欢

  • Mootools常用方法扩展(二)

    2009-01-11 18:22:00
  • 说说回车键触发表单提交的问题

    2009-02-03 13:25:00
  • 减少SQL Server死锁的方法

    2009-01-05 13:49:00
  • 略谈美国雅虎首页改版

    2009-07-26 18:34:00
  • 木鸟:ASP缓存类无错版

    2008-02-20 12:53:00
  • MYSQL 字符串操作

    2008-11-13 12:34:00
  • 如何获知IE和NC客户端的屏幕分辨率?

    2009-11-23 20:56:00
  • 用ASP在线创建Word与Excel文档

    2008-07-20 19:17:00
  • SQL Server 数据页缓冲区的内存瓶颈分析

    2012-08-21 10:49:11
  • 网页iframe元素应用浅析

    2009-04-11 18:11:00
  • SQL Server字符串切割函数

    2012-08-21 10:18:43
  • Data URI 和 MHTML

    2009-08-16 16:19:00
  • wap开发 完整的WML文档结构详解

    2008-05-21 13:39:00
  • 让IE6更快的走向灭亡

    2010-02-03 15:05:00
  • asp中access升级到sql server后要做的工作

    2007-08-11 13:35:00
  • SQL Server 数据库索引其索引的小技巧

    2012-07-11 15:55:02
  • text-overflow实现标题省略号功能

    2009-05-19 12:13:00
  • asp如何遍历目录及目录下的文件?

    2009-11-11 17:55:00
  • Web标准学习:CSS样式书写风格

    2008-03-25 09:37:00
  • IE下中英文字体不能对齐原因及解决

    2008-08-11 12:47:00
  • asp之家 网络编程 m.aspxhome.com