« xml document 对象属性手册CSS尺寸对照表 »

ASP网站设计中的表单验证

我们以实例来讲述验证方法。

1、验证输入的数字
假设一个文本框

<form name="form1" method="post" action="">
<input type="text" name="textfield">
</form>
'要求用户必须输入数字
if not isnumeric(Request.Form("textfield")) then
response.write "重新填写"
end if
'要求限制数字长度,如你要用户输入oicq号码
'此例限制了用户的输入只有为4到10位数字才有效
if len(Request.Form("textfield"))>10 or len(Request.Form("textfield"))<4 then
response.write "重新填写"
end if
当然上面用Request.Form和Request是一样的,随便你怎幺写了。

2、验证用户输入的邮件地址
'引用一段通用检测函数来说明
'由于检验程序较长,将其定义为一函数来调用
function IsValidEmail(email)
dim names, name, i, c
'Check for valid syntax in an email address.
IsValidEmail = true
names = Split(email, "@")
if UBound(names) <> 1 then
IsValidEmail = false
exit function
end if
for each name in names
if Len(name) <= 0 then
IsValidEmail = false
exit function
end if
for i = 1 to Len(name)
c = Lcase(Mid(name, i, 1))
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then
IsValidEmail = false
exit function
end if
next
if Left(name, 1) = "." or Right(name, 1) = "." then
IsValidEmail = false
exit function
end if
next
if InStr(names(1), ".") <= 0 then
IsValidEmail = false
exit function
end if
i = Len(names(1)) - InStrRev(names(1), ".")
if i <> 2 and i <> 3 then
IsValidEmail = false
exit function
end if
if InStr(email, "..") > 0 then
IsValidEmail = false

'出处  来自

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。