<%
rem ## 简单正则检测是否含有非法字符
rem ## str 待检测的字符串
rem ## badwordlist 过滤的字符串, 必须以 | 相隔
function ishavebadword(str, badwordlist)
dim strpattern
strpattern = badwordlist & "+"
dim oregex, omatch
set oregex = new regexp
oregex.ignorecase = true 不区分大小写
oregex.global = true
oregex.pattern = strpattern
set omatch = oregex.execute(str)
if omatch.count then
ishavebadword = true
else
ishavebadword = false
end if
end function
rem ## 简单正则替换非法字符, 以一个*代替
rem ## str 待检测的字符串
rem ## badwordlist 过滤的字符串, 必须以 | 相隔
function replacebadword(str, badwordlist)
dim strpattern
strpattern = badwordlist & "+"
dim oregex, omatch
set oregex = new regexp
oregex.ignorecase = true 不区分大小写
oregex.global = true
oregex.pattern = strpattern
replacebadword = oregex.replace(str, "*")
set oregex = nothing
end function
response.write("asp萧月痕xiaoyuehen " & ishavebadword("asp萧月痕xiaoyuehen", "xiaoyuehen|萧月痕") & "<br>")
response.write("asp萧月痕xiaoyuehen " & replacebadword("asp萧月痕xiaoyuehen", "xiaoyuehen|萧月痕") & "<br>")
rem ## 检测是否为,相隔的数字序列. 可用于表单的多选提交检测
rem ## str 待检测的字符串
function matchnumlist(str)
dim strpattern
strpattern = "^[0-9]{1,}(,[0-9]+){0,}$"
dim oregex, omatch
set oregex = new regexp
oregex.ignorecase = true 不区分大小写
oregex.global = true
oregex.pattern = strpattern
set omatch = oregex.execute(str)
if omatch.count then
matchnumlist = true
else
matchnumlist = false
end if
end function
response.write("6,1245,2122,456 " & matchnumlist("6,1245,2122,456") & "<br>")
response.write("6,1a45,2122,456 " & matchnumlist("6,1a45,2122,456") & "<br>")
response.write(",6,1245,2122,456 " & matchnumlist(",6,1245,2122,456") & "<br>")
response.write("6,1245,2122,456, " & matchnumlist("6,1245,2122,456,") & "<br>")
%>
