ASP特殊字符过滤

来源:百度知道 编辑:UC知道 时间:2024/05/10 09:39:26
我在网上看到一个关于ASP特殊字符过滤的函数,如下:
Function ChkInvaildWord(Words)
Const InvaildWords="select|update|delete|insert|@|--|," ''需要过滤得字符以“|”隔开,最后结束的字符必须是|

ChkInvaildWord=True
InvaildWord=Split(InvaildWords,"|")
inWords=LCase(Trim(Words))

For i=LBound(InvaildWord) To UBound(InvaildWord)
If Instr(inWords,InvaildWord(i))>0 Then
ChkInvaildWord=True
Exit Function
End If
Next
ChkInvaildWord=False
End Function
但是我不知道怎么用,
望高手指教。分数不够的话再加

就这么用:
<%
str="dshofghe98awyt9"
if ChkInvaildWord(str) then
response.write "你的输入含有非法字符"
response.end
end if
Function ChkInvaildWord(Words)
Const InvaildWords="select|update|delete|insert|@|--|," ''需要过滤得字符以“|”隔开,最后结束的字符必须是|

ChkInvaildWord=True
InvaildWord=Split(InvaildWords,"|")
inWords=LCase(Trim(Words))

For i=LBound(InvaildWord) To UBound(InvaildWord)
If Instr(inWords,InvaildWord(i))>0 Then
ChkInvaildWord=True
Exit Function
End If
Next
ChkInvaildWord=False
End Function
%>

这个函数不是特殊字符过滤的函数,而是判断字符串是否合法的函数。
一,自定义区间:="select|update|delete|insert|@|--|," 是你可以自定义的
二,函数的调用方式为:call ChkInvaildWord(Words) 或把这个函数返回的值赋给一个变量val=ChkInvaildWord(Words).例如你想判断字符串“aaaselect”是否合法,就应该这样写:val=ChkInvaildWord(“aaaselect”)。
三,这个函数通常用于判断输入的字符串是否合法,不合法则返回true,合法则返回false。然后你可以根据返回值的真与假,来进行下一步操作,像重新输入啊,