以下是网上找的一个ASP版垃圾信息判断函数,主要功能根据您设置的关键字不只能过滤反动、色情信息,而且也可以过滤广告机器人发布的垃圾广告、回复者不想透露的个人联系信息等。
'--- 函数名:ReplaceContactInfo ---
'--- 参数:tStr(要过滤的字符串) tRepStr(若经判断不合法要显示的内容) tTrue(是否应用过滤或屏蔽功能,可动态判断这里只需要值为true或false的结果) ---
'--- 功能:过滤电话、邮件、网址、色情、反动 ---
Function ReplaceContactInfo(tStr,tRepStr,tTrue)
fctRepStr=tRepStr
dim fctReplaceContactInfo,dimTempContactInfo
if tTrue and not CheckNull(tStr) then
if CheckNull(tRepStr) then
tRepStr="<span style='color:#999999' title='联系信息涉及隐私故屏蔽'>**此信息被隐藏,请负责人员登录后查看**</span>"
end if
set regEmpty = New RegExp
regEmpty.Pattern="这里填写网络禁用关键字多个用|分隔,关键字下载见本文结尾处"
regEmpty.IgnoreCase = false ' 设置是否区分字符大小写。
regEmpty.Global = True ' 设置全局可用性。
dimIsInStrTStrPat=regEmpty.test(tStr)
if dimIsInStrTStrPat then
fctReplaceContactInfo="<span style='color:#999999;' title='净化网络'>系统检测到此信息含有反动或色情等违规内容,故而屏蔽;请珍惜每一个交流机会。</span>"
else
on error resume next
if CheckNull(tStr) then
SdkStr=""
exit function
end if
dim sList,dList,i,s,RegEx
dimTempContactInfo=tStr
sList="1|2|3|4|5|6|7|8|9|0|-|_|~|/|。|:|&|@|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
dList="1|2|3|4|5|6|7|8|9|0|-|_|~|/|.|:|&|@|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
s=ubound(split(sList,"|"))
'过滤大写字符为小写字符
for i=0 to s
tStr=replace(tStr,split(sList,"|")(i),split(dList,"|")(i))
next
Set RegEx=New RegExp
RegEx.Pattern="(\(\d{2,4}\)|(\d{3,4}-?))\d{7,8}|\d{6,15}|0?13\d{1}\d{8}|((\w)|[-]|[.])+@(((\w)|[-])+[.])+[a-z]{2,4}|http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?|([\w-]+\.)+(?:[a-z]{2,3})+(\/[\w- .\/?%&=]*)?"'处理电话号码和电子邮件、网址
RegEx.IgnoreCase=True
RegEx.Global=True
fctReplaceContactInfo=RegEx.Replace(tStr,tRepStr)
Set RegEx=Nothing
if (ubound(split(fctReplaceContactInfo,tRepStr))>1 and (ubound(split(fctReplaceContactInfo,tRepStr))>6 or inStr(fctReplaceContactInfo,"市场")>0 or (inStr(fctReplaceContactInfo,"公司")>0 and ubound(split(fctReplaceContactInfo,tRepStr))>3 and inStr(fctReplaceContactInfo,"贵公司")<0) or inStr(fctReplaceContactInfo,"全体员工")>0 or inStr(fctReplaceContactInfo,"href=")>0 or inStr(fctReplaceContactInfo,"url=")>0) or inStr(fctReplaceContactInfo,"href=")>5 or inStr(fctReplaceContactInfo,"url=")>3) then
fctReplaceContactInfo="<span style='color:#999999;' title='拒绝广告,净化网络'>系统检测到此信息为疑似广告内容,故而屏蔽;请珍惜交流机会,不要在此发布广告,谢谢合作。</span>"
elseif not CheckNull(fctRepStr) then
fctReplaceContactInfo=dimTempContactInfo
end if
end if
else
fctReplaceContactInfo=tStr
end if
ReplaceContactInfo=fctReplaceContactInfo
End Function
''检查一个字符串是否为空
Function checkNull(strCheck)
if isnull(strCheck) or trim(strCheck) = "" then
checkNull = true
else
checkNull = false
end if
End Function
'--- 参数:tStr(要过滤的字符串) tRepStr(若经判断不合法要显示的内容) tTrue(是否应用过滤或屏蔽功能,可动态判断这里只需要值为true或false的结果) ---
'--- 功能:过滤电话、邮件、网址、色情、反动 ---
Function ReplaceContactInfo(tStr,tRepStr,tTrue)
fctRepStr=tRepStr
dim fctReplaceContactInfo,dimTempContactInfo
if tTrue and not CheckNull(tStr) then
if CheckNull(tRepStr) then
tRepStr="<span style='color:#999999' title='联系信息涉及隐私故屏蔽'>**此信息被隐藏,请负责人员登录后查看**</span>"
end if
set regEmpty = New RegExp
regEmpty.Pattern="这里填写网络禁用关键字多个用|分隔,关键字下载见本文结尾处"
regEmpty.IgnoreCase = false ' 设置是否区分字符大小写。
regEmpty.Global = True ' 设置全局可用性。
dimIsInStrTStrPat=regEmpty.test(tStr)
if dimIsInStrTStrPat then
fctReplaceContactInfo="<span style='color:#999999;' title='净化网络'>系统检测到此信息含有反动或色情等违规内容,故而屏蔽;请珍惜每一个交流机会。</span>"
else
on error resume next
if CheckNull(tStr) then
SdkStr=""
exit function
end if
dim sList,dList,i,s,RegEx
dimTempContactInfo=tStr
sList="1|2|3|4|5|6|7|8|9|0|-|_|~|/|。|:|&|@|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
dList="1|2|3|4|5|6|7|8|9|0|-|_|~|/|.|:|&|@|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z"
s=ubound(split(sList,"|"))
'过滤大写字符为小写字符
for i=0 to s
tStr=replace(tStr,split(sList,"|")(i),split(dList,"|")(i))
next
Set RegEx=New RegExp
RegEx.Pattern="(\(\d{2,4}\)|(\d{3,4}-?))\d{7,8}|\d{6,15}|0?13\d{1}\d{8}|((\w)|[-]|[.])+@(((\w)|[-])+[.])+[a-z]{2,4}|http:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?|([\w-]+\.)+(?:[a-z]{2,3})+(\/[\w- .\/?%&=]*)?"'处理电话号码和电子邮件、网址
RegEx.IgnoreCase=True
RegEx.Global=True
fctReplaceContactInfo=RegEx.Replace(tStr,tRepStr)
Set RegEx=Nothing
if (ubound(split(fctReplaceContactInfo,tRepStr))>1 and (ubound(split(fctReplaceContactInfo,tRepStr))>6 or inStr(fctReplaceContactInfo,"市场")>0 or (inStr(fctReplaceContactInfo,"公司")>0 and ubound(split(fctReplaceContactInfo,tRepStr))>3 and inStr(fctReplaceContactInfo,"贵公司")<0) or inStr(fctReplaceContactInfo,"全体员工")>0 or inStr(fctReplaceContactInfo,"href=")>0 or inStr(fctReplaceContactInfo,"url=")>0) or inStr(fctReplaceContactInfo,"href=")>5 or inStr(fctReplaceContactInfo,"url=")>3) then
fctReplaceContactInfo="<span style='color:#999999;' title='拒绝广告,净化网络'>系统检测到此信息为疑似广告内容,故而屏蔽;请珍惜交流机会,不要在此发布广告,谢谢合作。</span>"
elseif not CheckNull(fctRepStr) then
fctReplaceContactInfo=dimTempContactInfo
end if
end if
else
fctReplaceContactInfo=tStr
end if
ReplaceContactInfo=fctReplaceContactInfo
End Function
''检查一个字符串是否为空
Function checkNull(strCheck)
if isnull(strCheck) or trim(strCheck) = "" then
checkNull = true
else
checkNull = false
end if
End Function
一些过滤的垃圾词汇表
发表评论