Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Profanity filter in chat application help!

Status
Not open for further replies.

starblood

Technical User
Feb 28, 2001
63
0
0
GB
I'm running an ASP chat application on the site I administer and it has a profanity filter that works along the the line of:

msgLine=Replace(msgline, "bugger", "b****er")
msgLine=Replace(msgline, "swine", "sw**ne")

.......but obviously with worse words than these :)

So as users get wise and start using "b.ugger" and "bu_gger" I will have to add new lines to the code to ban those words. What I'd like to do is kick them out if they swear - a solution has been suggested by a colleague:

if msgLine<>Replace(msgline, &quot;bugger&quot;, &quot;b****er&quot;) then
msgLine=Replace(msgline, &quot;bugger&quot;, &quot;b****er&quot;)
Response.Redirect &quot;swear.asp&quot;

and this works but is going to prove unweidly and cumbersome if I have to use it for every bad word. Anyone got any suggestions on how to do it more elegantly? Treat me as an idiot when it comes to explaining as I am not a programmer by a long way!
 
Trouble is computers are even dumber than any human, so we have to tell them what a profanity is and then what to do about it. There are some dictionaries of swear words, but you look as if you are on the right tracks.

There are more sophisticated approaches that are way beyond the scope of asp and databases - check out automomy for inspiration.

For a simple implementation alng the lines you are using check out WebWizGuide.com - they provide an open source forum that has this facility.
 
When it come to string search and replace, the command
Code:
replace
is not efficient at all!

Use the magical object
Code:
RegExp
. I have made a chat area that accepts smilies of any kind, like :) or :)

here how it is used:
Code:
 set regEx = new RegExp
 regEx.Global = true     'make search to ALL matches
 regEx.Pattern = &quot;b\Wu\Wg\Wg\We\Wr&quot;
 msgLine = regEx.Replace (strString,&quot;b****r&quot;) 'make replacement
 
'to test match only
 if reqEx.test (strString) then response.redirect &quot;swear.asp&quot;

focus on the Pattern part. you must make a combination that covers all possible cases that you expect people will use. Like b.ugger and b_ugger ....

Salibas
 
Thanks Salibas, I'm onto it!

I've actually managed to cobble together a bad word database by adapting a guestbook script at WebWizGuide.com, as recommended by Mylesorme (amazed myself as I am not a programmer as previously stated and most of my dealings in code have been HTML and Javascript)

Anyway, if anyone wants to see the chat application in question, it is here:


logon: guest
password: guest

It is quiet at the moment, students are on holiday!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top