表单验证的高难度问题。

exten 2003-12-31 05:11:29
<% for i=1 to 22 %>
<tr>

<td colspan="2">
<input type="text" name="txt_item_no<%= i %>" size="22">
</td>
<td width="17%">
<input type="text" name="txt_date_make<%= i %>" size="16">
</td>
<td width="17%">
<input type="text" name="txt_term_use<%= i %>" size="18">
</td>
<td width="8%">
<input type="text" name="txt_num<%= i %>" size="8">
</td>

</tr>
<% next %>


提交时,要求:
1、
name="txt_term_use<%= i %>" 输入的文件格式必须为日期型式,并且格式为2004-01-08,并且输入的日期至少为“当前日期+7天”,请问,怎么做?


2、
name="txt_num<%= i %>"的格式必须为数字形式。
...全文
30 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jrhjrh 2003-12-31
  • 打赏
  • 举报
回复
bt
cheqiang 2003-12-31
  • 打赏
  • 举报
回复
1、ASP自动生成就OK了,防止别人更改,可以使用一个hidden,提交的时候提交hidden里的值
2、用正则表达式

<script language="javascript">
function checkform() {
var reg=/\d/g;
alert(document.all.length);
for (i=0;i<document.all.length;i++) {
if (document.all[i].type=="text") {
if (reg.test(document.all[i].value)) {
alert("OK");
} else {
alert("请重新输入内容!");
document.all[i].focus();
return false;
}
}
}
}
</script>
ranmavip 2003-12-31
  • 打赏
  • 举报
回复
数字形式的INPUT
<input type="text" onkeypress="return event.keyCode>=48&&event.keyCode<=57" onpaste="return !clipboardData.getData('text').match(/\D/)" style="ime-mode:Disabled" ondragenter="return false" size="8">

日期格式的INPUT
<html><head></head><body><script language=vbs>
sub error_msg
alert("日期不正确!"&chr(13)&chr(10)&"正确格式必须是2004-01-08")
end sub
sub error_msg2
alert("输入的日期至少为当前日期+7")
end sub
function checkdate()
val=document.fm.ck.value
if val="" then
call error_msg
exit function
end if
mydatepart=split(val,"-")
if ubound(mydatepart)<>2 then
call error_msg
exit function
end if
if not isnumeric(mydatepart(0)) or len(mydatepart(0))<>4 then
call error_msg
exit function
end if
if not isnumeric(mydatepart(1)) or len(mydatepart(1))<>2 then
call error_msg
exit function
end if
if not isnumeric(mydatepart(2)) or len(mydatepart(2))<>2 then
call error_msg
exit function
end if
if not isdate(val) then
call error_msg
exit function
end if
if DateDiff("d",date,val)<7 then
call error_msg2
exit function
end if
end function
</script>
<form name=fm>
<input type="text" onBlur="checkdate()" value="" name=ck>
</form>
</body></html>
Pandaxm 2003-12-31
  • 打赏
  • 举报
回复
我是这样做的
<FORM METHOD=POST ACTION="aa.asp">
<TABLE>
<% For i=1 to 22 %>
<TR>
<TD><input type="text" name="txt_item_no" size="22"></TD>
<TD><input type="text" name="txt_date_make" size="16"></TD>
<TD><input type="text" name="txt_term_use" size="18"></TD>
<TD><input type="text" name="txt_num" size="8"></TD>
</TR>
<% Next %>
</TABLE>
</FORM>

aa.asp
<%
If Request.Form("txt_term_use")="" Then
Response.write "<SCRIPT LANGUAGE=JavaScript>alert('txt_term_use不可为空');history.back();</SCRIPT>"
Response.End
Else
term_use = Reques.Form("txt_term_use")
term_use_num = Split(term_use,",")
For i=0 to ubound(term_use_num)
If Not IsDate(term_use_num(i)) Or term_use_num(i)="" Then
Response.write "<SCRIPT LANGUAGE=JavaScript>alert('txt_term_use不是日期格式');history.back();</SCRIPT>"
Response.End
ElseIf CDate(term_use_num(i)>(Date()+7) Then
Response.write "<SCRIPT LANGUAGE=JavaScript>alert('txt_term_use要大于当前日期7天');history.back();</SCRIPT>"
Response.End
End If
Next
End If


If Request.Form("txt_num")="" Then
Response.write "<SCRIPT LANGUAGE=JavaScript>alert('txt_term_use不可为空');history.back();</SCRIPT>"
Response.End
Else
txt_num = Request.FOrm("txt_num")
txt_nums = Split(txt_num,",")
For i=0 to ubound(txt_nums)
If Not IsNumeric(txt_nums(i) Then
Response.write "<SCRIPT LANGUAGE=JavaScript>alert('txt_num不是数字');history.back();</SCRIPT>"
Response.End
End If
Next
End If
%>

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧