社区
ASP
帖子详情
网页中有一文本框,如何约束用户输入格式
lyf123
2001-07-19 11:00:31
网页中有一文本框,如何约束用户输入格式。比如我只允许用户按照YYYY-MM-DD格式输入日期
...全文
72
3
打赏
收藏
网页中有一文本框,如何约束用户输入格式
网页中有一文本框,如何约束用户输入格式。比如我只允许用户按照YYYY-MM-DD格式输入日期
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
hydnoahark
2001-07-19
打赏
举报
回复
不如用户日历控件(ocx的或js/vbs的)
freezwy
2001-07-19
打赏
举报
回复
对了,最好在客户端检查的函数全部写成一个JS然后在需要的地方引用就是了。
freezwy
2001-07-19
打赏
举报
回复
客户端检查,给你段我的代码,给分!
<script language=javascript>
function parseYMD(theYear,theMonth,theDay) {
theYear=parseNum(theYear)
theMonth=parseNum(theMonth)
theDay=parseNum(theDay)
if ((theYear < 1900) || (theYear > 3000)){
return 1
}
if (theMonth < 1 || theMonth > 12){
return 2
}
if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
(theDay <1 || theDay > 31)
){
return 3
}
if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
(theDay <1 || theDay > 30)
){
return 3
}
if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){ //闰年
if (theMonth==2 && (theDay <1 || theDay > 29) )
return 3
}
else //平年
if (theMonth==2 && (theDay <1 || theDay > 28) )
return 3
return 0
}
function isInvalidDate(theDate,separator){
default_style=1
if (theDate.length>10 || theDate.length<8)
return true
idx1=theDate.indexOf(separator)
if (idx1==-1)
return true
idx2=theDate.indexOf(separator,idx1+1)
if (idx2==-1)
return true
if (isInvalidDate.arguments.length>2)
default_style=isInvalidDate.arguments[2]
if (default_style<1 || default_style>9){
alert("传入参数有误!请检查。")
return true
}
if (default_style==1){
theYear=theDate.substring(0,idx1)
theMonth=theDate.substring(idx1+1,idx2)
theDay=theDate.substring(idx2+1)
}
if (default_style==2){
theMonth=theDate.substring(0,idx1)
theDay=theDate.substring(idx1+1,idx2)
theYear=theDate.substring(idx2+1)
}
if (theDay.length>2)
return true
if (parseYMD(theYear,theMonth,theDay)>0)
return true
else
return false
}
function checkinput()
{
if (isInvalidDate(document.regform.birthday.value,"-"))
{
alert("您的出生年月填写错误,格式是2001-6-1!");
document.regform.birthday.focus();
return false;
}
return true;
}
</script>
调用就可以了。
<form name=regform action=xx.asp method=post onsubmit="return checkinput();">
....
</form>
够用了吧。
。net图书管理系统设计方案
函数依赖性就是一个表中的字段间不应该有计算关系,如一个表
中有
单价字段、数量字段,就不应该有一个总金额字段。如果程序运行过程中需要总金额,可以实时计算。不过在一些较常用的表中,我们可以适当地保留冗余字段...
超实用的jQuery代码段
包含
网页
效果、DOM元素与属性、HTML事件、CSS样式、
用户
输入
自动完成、拖放、图形图像、AJAX、算法、jQuery Mobile应用、浏览器、Cookies等jQuery技术内容,对提高网站开发人员和设计人员的jQuery技术水平有指导作用...
使用Javascript进行前端验证
设计简单的
用户
注册页面,其中包括“请
输入
密码”和“请再次
输入
密码”两个
文本框
使用Javascript对“请
输入
密码”和“请再次
输入
密码”两个
文本框
的内容进行验证,如果两个
文本框
的内容不一样则显示“两次
输入
的...
JS高级程序设计——第14章 表单脚本 14.2
文本框
脚本
在 HTML 中,有两种方式来表现
文本框
:一种是使用<input>元素的单行
文本框
,另一种是使用 <textarea>的多行
文本框
。这两个控件非常相似,而且多数时候的行为也差不多。不过,它们之间仍然存在一些重要的...
用户
输入
的防注入总结 简介和第三、四、五步
如果这些文来自于
用户
输入
,数据库或者一个本地文件,请确保总是这样做. 同样地,如果您书写的URL里面包含不安全的字符因为他们来自于
用户
输入
内容,数据库等,使用HttpUtility.UrlEncode方法进行编码. 为了防止存储...
ASP
28,390
社区成员
357,068
社区内容
发帖
与我相关
我的任务
ASP
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
复制链接
扫一扫
分享
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章