首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > 代码乐园 >
    7i24 .Com  
  检测提交数据的函数

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


转自站: 学习资讯



  2002年1月9日  阅读 1067 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 一个字符中的处理例子 - 格式化指定电话号码
下一篇: 两个字符串的处理函数
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利