檢測是否含有禁止字串
來源:互聯網
上載者:User
<%
'------------------------------------
'檢測是否含有禁止字串,如果禁止字串出現次數為5,測返回True
'參數說明:
'badWordList = 禁止字元列表(以,號隔開)
'str = 被檢測字串
'傳回值 Boolean
'小男 2006
'更新no_mIss'------------------------------------
Function checkBadWord(ByVal badWordList,ByVal str)
str=""&str:CheckBadWord = False
Dim regEx,Matches
Set regEx = New RegExp
regEx.Global = True
'--------處理-----------
regEx.Pattern = "[^/u4E00-/u9FA5]" '取中文
str2 = regEx.Replace(str,"")
regEx.Pattern = "[^A-Za-z]"
str3 = regEx.Replace(str,"") '取英文
'------------------------
str = str3 & str2
regEx.IgnoreCase = True
regEx.Pattern = Replace(Replace(""&badWordList,"|","/|"),",","|")
Set Matches = regEx.Execute(str)
'CheckBadWord = regEx.Test(str) ''返回是否含有禁用字串
If Matches.Count = 5 Then CheckBadWord = True '如果禁止字元出現5次,則返回True
Set regEx = Nothing
End Function
Dim a,b
a=Request.Form("a")
b="我日,abc,測試"
Response.Write checkBadWord(b,a)
%>
<form method="post" action="">
<input name="a" value="<%=a%>" />
<input type="submit" />
</form>