检测提交数据的函数(转)

本文介绍了一个用于ASP中表单数据验证的自定义函数,该函数能够检查提交数据的长度是否符合预设的范围,并排除非法字符,确保数据的有效性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个检测提交数据的函数
在我们用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("你所提交的数据超过系统允许的长度!请重新输入")
response.end
end if
end if
'----判断数据是否太小
if small<>"no" then
if chresponse.write("你所提交的数据低于系统允许的长度!请重新输入")
response.end
end if
end if
chkchar(str) '调用检测是否有非法字符函数
sink=str
end function

'----------检测是否有非法字符函数
function chkchar(char)
'对用户名进行判断
if instr(char,"'") then
 response.write("非法字符,请重新输入!请重新输入")
 response.end
 end if
if instr(char,"'") then
 response.write("非法字符,请重新输入!请重新输入")
 response.end
end if
if instr(char,"|") then
 response.write("非法字符,请重新输入!请重新输入")
 response.end
end if
end function


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124744/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124744/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值