ASP-Coding.com

ASP programming techniques and ASP web developer tutorials.
Welcome to ASP-Coding.com Sign in | Join | Help
in Search

ASP Tutorial Articles

ASP coding tutorials and articles to help you code asp based websites and pages

ASP Swear Filter

In the past couple of years I, and my colleague, have created several online communities (quite successful ones i might add) and two fairly important parts of these communities are the forums and chatrooms. If you've used online forums/message boards before then you've probably noticed that the majority of them use a swear filter / language filter. Because we didn't use an "Out of the box" forum package for our communities we had to create our own filters using ASP / VBScript. Here is an example of a fairly simple ASP based language filter function:

Function Language_Filter(s)

dim badwordsfilter,badWords,regEx,badword
badwordsfilter="word1,word2,word3,"
badWords = Split(badWordsFilter, ",")
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
For Each badWord In badWords
badWord = Trim(badWord)
regEx.Pattern = "(\s"&badWord&"\s)|(^"&badword&")|(^"&badword&"$)|("&badword&"$)"
regEx.Pattern = "\b"&badWord&"\b"
s = regEx.Replace(s, padBadWordWithAsterisks(badWord))
Next
Language_Filter = s
Set RegEx=Nothing
end function

Bear in mind that this would probably be used after any other "cleaning" of the input text for invalid / dangerous characters. (We will look at that in another post)

Comments

No Comments
Powered by Community Server (Non-Commercial Edition), by Telligent Systems