核心提示:%str='dshofghe98awyt9'if ChkInvaildWord(str) thenresponse.write '你的輸入含有非法字符'response.endend ifFunction ChkInvaildWord(Words)Const InvaildWords='select…
itE-SPACE: normal; BACKGROUND: url(http://yx095.info/static/image/commoncodebg.gif) rgb(247,247,247) repeat-y 0px 0px; LETTER-SPACING: normal; COLOR: rgb(68,68,68); BORDER-TOP: rgb(204,204,204) 1px solid; BORDER-RIGHT: rgb(204,204,204) 1px solid; WORD-SPACING: 0px; PADDING-TOP: 10px; -webkit-text-stroke-width: 0px" class=blockcode>
<%
str="dshofghe98awyt9"
if ChkInvaildWord(str) then
response.write "你的輸入含有非法字符"
response.end
end if
Function ChkInvaildWord(Words)
Const InvaildWords="select|update|delete|insert|@|–|," ''需要過(guò)濾得字符以“|”隔開(kāi),最后結(jié)束的字符必須是|
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
%>
例如 你現(xiàn)在接受了一個(gè)STR的值
那么就直接 ChkInvaildWord(STR)
如果STR中間有特殊字符 那么你就得到了FALSE
如果沒(méi)有 那么你就得到TRUE
一般都都會(huì)在前面加上IF判斷。。
未經(jīng)允許不得轉(zhuǎn)載:445IT之家 » ASP特殊字符過(guò)濾的函數(shù)