<%
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>")
%>
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>")
%>
相关信息
- 关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 管理登陆
- Copyright © 2003-2007 ZhuYe123.COM. All Rights Reserved . 粤ICP备05072659号
- 致力于中国个人网站发展,我们一直在努力!