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

Filter unwanted usernames or offensive or dirty words

, 8 Feb 2006
Rate this:
Please Sign up or sign in to vote.
Login names, article titles, and other user input on public sites rated G need help in filtering out the trash.

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 Intact Partners Inc
United States United States
My company specializes Microsoft Windows Azure Cloud Computing in private and public sector consulting. We have a number of highly visible successful cloud projects including Florida Voter Registration System for the elections in 2012.
Intact develops not just the cloud solution, we develop your organization. We know that the leap to cloud is a jump that most are unable to make. At the same time the demands for mobile devices and applications drain all the energy. Intact has successfully helped large business and government over the hump. We can help you too.
Visit us at: http://www.itintact.com
 
View my bio on LinkedIn.com at www.linkedIn.com/in/laultman
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
QuestionI think we need SoundEx too PinmemberAbishek Bellamkonda14-Sep-06 13:52 
GeneralProblem Pinmembersnoopybb19-Feb-06 16:36 
GeneralRe: Problem PinmemberLarry Aultman20-Feb-06 7:34 
GeneralMIssing the download file PinmemberAl Ortega8-Feb-06 4:56 
GeneralRe: MIssing the download file PinmemberLarry Aultman8-Feb-06 5:22 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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