Click here to Skip to main content
Click here to Skip to main content

Filter unwanted usernames or offensive or dirty words

By , 8 Feb 2006
 

Introduction

Public sites and those "Rated G" are no place for words we all consider offensive. Commedian George Carlin has made lots of money with his Seven Dirty Words, and the rest of humanity seems to want to top him. If you have a site where users can create input, then sometimes you just might want to filter it.

WordFilter Project

This project is so simple. There is nothing fancy at all, unzip the files in a new folder and create a virtual directory in IIS to the folder. Since this is a .NET 2.0 project, you will need to set the properties in IIS on the ASP.NET tab to .NET 2.0. Make sure the virtual directory is an application, and that it is configured to run scripts.

The working code is in a class file in the APP_CODE folder. In that file are two versions of a string of words to test against.

The test is performed in two stages. First, the input word is run against a string to find a match embedded in the test string. If it is found, then the function returns "true". If that quick match fails, then a slightly more exhaustive check is preformed by taking the exclusion word list and testing the input string against it looking for a match. Again, if a match occurs, "true" is returned.

These methods are able to stem a word to produce a match: e.g., test (stem) test, tests, tested, testing, intestional will all return "true".

I have been asked, "Why have two methods?" There many times when the stem would produce a match when it is a perfectly acceptable word. Such as the name Mitchell. The first test looks for word matches while the second test performs stem/embedded matching. In my example project, I have the same words in both lists, but that is not required. Often, you will want to find specific words to filter, but not stems or embedded.

Limitations

A big list can take a long time. Also, no "pre-filtering" is done in this project. In a real world project, you most likely will want to do some initial range test or Regular Expression test before you test the filter. I run this after every thing else has cleared.

Naturally, this is not a complete list. You will certainly want to modify it for your own use.

Possibilities

The first thing that comes to mind is that you could simply drop the wordfilter.cs file directly into a project that you have and it is ready to go. You could implement it as a static class, then it would not need to be instanced in your code.

You could implement different lists that are applicable to the type of input expected.

Summary

I hope you find the code interesting and useful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Larry Aultman
CEO BizBanc LLC
United States United States
View my bio on LinkedIn.com at www.linkedIn.com/in/laultman

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionI think we need SoundEx too PinmemberAbishek Bellamkonda14-Sep-06 13:52 
GeneralProblem Pinmembersnoopybb19-Feb-06 16:36 
GeneralMIssing the download file PinmemberAl Ortega8-Feb-06 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 8 Feb 2006
Article Copyright 2006 by Larry Aultman
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid