|
|
|
7i24.Com不停为您服务 检测提交数据的函数
作者: lzppcc
一个检测提交数据的函数
在我们用ASP读取提交过的信息时,有时我们想要某些字段不能为空,或不能低于几位,或不能大于几位.一般都是
在读完之后再用程序判断.以下是一个本人写的检测提交函数.
调用方法:
sink("要读取表单名","提交过来数据方式",最大允许长度,最小允许长度)
如:要读取提交过来name的值,提交的方式是post,最大允许长度为15字符,最小为5字符
name=sink("name","post",15,5)
如果提交的方式为get则是
name=sink("name","get",15,5)
如是你不允许最大或最小的长度为空则是
name=sink("name","post","no","no")
以来是本人的函数:
'-------------取出提交过来的信息并规化----------
function sink(str,ty,big,small) 'str 提交的变量名 ty 所有的提交方式 (post 或 get) big为规定字符的
长变 small系统允许最小字符
if ty="post" then
str=trim(request.form(str))
else
if ty="get" then
str=trim(request(str))
else
response.write("函数提交变量不对应为post或get方式" )
response.end
end if
end if
ch=int(len(str))
'---判断数据是否超长
if big<>"no" then
if ch>big then
response.write("你所提交的数据超过系统允许的长度!请<a href='vbscript:history.back'>重新输入</a>")
response.end
end if
end if
'----判断数据是否太小
if small<>"no" then
if ch<small then
response.write("你所提交的数据低于系统允许的长度!请<a href='vbscript:history.back'>重新输入</a>")
response.end
end if
end if
chkchar(str) '调用检测是否有非法字符函数
sink=str
end function
'----------检测是否有非法字符函数
function chkchar(char)
'对用户名进行判断
if instr(char,"'") then
response.write("非法字符,请重新输入!请<a href='vbscript:history.back'>重新输入</a>")
response.end
end if
if instr(char,"'") then
response.write("非法字符,请重新输入!请<a href='vbscript:history.back'>重新输入</a>")
response.end
end if
if instr(char,"|") then
response.write("非法字符,请重新输入!请<a href='vbscript:history.back'>重新输入</a>")
response.end
end if
end function
转自站: 学习资讯
|
|
|