Stupid Web Tricks: Censor profanity on your site
Takeaway: Use this Web trick to censor your users when they offer too much information about their personal lives (or preferences) on your site.
Click here for our complete list of Stupid Web Tricks.By Holly Cunningham
(6/8/01)
A short while ago, we served up a calendar form with a blank field that let the user input some happy thoughts about what they might want to do at some distant place and time. Innocent enough, n'est-ce pas? But if you've implemented that form yourself or otherwise invited the suggestions of hormonally charged shut-ins via your Web site, you may find that some people's idea of excitement includes things you want to hear only over drinks in a pricey hotel bar in a country with less restrictive laws--if at all. We have a way to help your more imaginative viewers on the path to better manners and save you valuable time that you'd otherwise spend puzzling out the grammar and mechanics of grade-school Henry Millers.
What I don't want to have to visualizeThe most difficult thing will be creating your list of "I don't want to see that." First, paste the following script into the
<head> of your page. Click here.
Find the variable numberOfWords and make it equal to the number of words and phrases on your personally offensive hit list. Edit the word array with your list. You may also change the alert that appears toward the end of the script when users enter a proscribed word, and you can alter the message variable at the top that replaces user-entered text.
Keep the form formal
For each form field that you want to keep unsullied, add this script: onBlur = "this.value = checkForProfanity(this.value);". For example, if you had a text input field, the code should look like this:
<INPUT type="text" onBlur = "this.value = checkForProfanity(this.value);" >
Remember, the noxious words that you're trying to exclude have many permutations (think gerunds), so include all the variants that you can think of in your list, since only exact matches will be weeded out.
Our thanks to Kenneth Rose, the originator of the onBlur Antiprofanity JavaScript, though we may have to disagree about what is offensive.
Holly Cunningham, a frequent contributor to CNET Builder.com, is a freelance Web designer who works primarily to keep her Chihuahua in furs.
SponsoredWhite Papers, Webcasts, and Downloads
- Next Generation Mobility Now Sprint
- Live Webcast: Simplified IT with Software-as-a-Service (SaaS) ZDNet
- Microsoft SQL Server 2005: Deployment and Tests in an iSCSI SAN Dell EqualLogic
- The Shortcut Guide to Managing Disk Fragmentation - Chapter 1 Diskeeper
- Nextel Direct Connect Fact Sheet Sprint
Article Categories
- Security
- Security Solutions, IT Locksmith
- Networking and Communications
- E-mail Administration NetNote, Cisco Routers and Switches
- CIO and IT Management
- Project Management, CIO Issues, Strategies that Scale
- Desktops, Laptops & OS
- Windows 2000 Professional, Microsoft Word, Microsoft Excel, Microsoft Access, Windows XP,
- Data Management
- Oracle, SQL Server
- Servers
- Windows NT, Linux NetNote, Windows Server 2003
- Career Development
- Geek Trivia
- Software/Web Development
- Web Development Zone, Visual Basic, .NET





