Saturday, August 16, 2008

Filter bad language with Delphi / Pascal...

This has been adapted from a ISAPI web application. The first step is to fill a TStringList with a list of bad words, or even characters that you don't want to save into your database.

I've call my StringList BWSL. After initializing the StringList, and adding the words, loop through and see if any of the words you've added are present.

If they are, redirect, or use other handling depending on the type of application you're writing. My form element on the calling web page is in the variable "Tag"


for I:=0 to BWSL.Count-1 do
if pos (BWSL.Strings[I], LowerCase(tag)) > 0 then begin
Response.SendRedirect(Request.ScriptName+'/BadRequest?Bid=6&Extra=The_Word,_Character,_or_Phrase,_' + BWSL.Strings[I] +'_is_Prohibited.');

No comments: