欢迎光临
我们一直在努力

几个简单的正则-ASP教程,ASP应用

建站超值云服务器,限时71元/月

<%

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>")

%>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 几个简单的正则-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章