JavaScript DHTML/Page Components/Word Filter
Word Filter 2.0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Word Filter 2.0</title>
<style type="text/css">
.ip{border:#000000 solid 1px; width:80%}
.btn{border:#000000 solid 1px; background:#EFEFEF; font-weight:bold; cursor:hand}
.link{font-family:verdana,arial,helvetica; font-size:8pt; color:#FFFFFF}
.link:hover{font-family:verdana,arial,helvetica; font-size:8pt; color:#CCCCFF}
</style>
<!--BEGIN WORD FILTER JAVASCRIPT-->
<script language="JavaScript">
// Word Filter 2.0
// (c) 2002 Premshree Pillai
// Created : 29 September 2002
// http://www.qiksearch.ru
// http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.ru
var swear_words_arr=new Array("fuck","bloody","war","terror","ass");
var swear_alert_arr=new Array();
var swear_alert_count=0;
function reset_alert_count()
{
swear_alert_count=0;
}
function wordFilter(form,fields)
{
reset_alert_count();
var compare_text;
var fieldErrArr=new Array();
var fieldErrIndex=0;
for(var i=0; i<fields.length; i++)
{
eval("compare_text=document." + form + "." + fields[i] + ".value;");
for(var j=0; j<swear_words_arr.length; j++)
{
for(var k=0; k<(compare_text.length); k++)
{
if(swear_words_arr[j]==compare_text.substring(k,(k+swear_words_arr[j].length)).toLowerCase())
{
swear_alert_arr[swear_alert_count]=compare_text.substring(k,(k+swear_words_arr[j].length));
swear_alert_count++;
fieldErrArr[fieldErrIndex]=i;
fieldErrIndex++;
}
}
}
}
var alert_text="";
for(var k=1; k<=swear_alert_count; k++)
{
alert_text+="\n" + "(" + k + ") " + swear_alert_arr[k-1];
eval("compare_text=document." + form + "." + fields[fieldErrArr[0]] + ".focus();");
eval("compare_text=document." + form + "." + fields[fieldErrArr[0]] + ".select();");
}
if(swear_alert_count>0)
{
alert("The form cannot be submitted.\nThe following illegal words were found:\n_______________________________\n" + alert_text + "\n_______________________________");
return false;
}
else
{
return true;
}
}
</script>
<!--END WORD FILTER JAVASCRIPT-->
</head>
<body bgcolor="#FFFFFF">
<table cellspacing="0" cellpadding="0" bgcolor="#0066CC" align="center" width="446"><tr><td></td></tr></table>
<table cellspacing="0" cellpadding="0" bgcolor="#0066CC" align="center" width="448"><tr><td></td></tr></table>
<table style="border:#0066CC solid 2px; width:450px" align="center" cellspacing="0" cellpadding="0"><tr><td>
<table style="width:100%; background:#0066CC"><tr><td align="middle"><span style="font-family:courier new,courier,verdana,arial; font-weight:bold; font-size:30pt; color:#FFFFFF; filter:Shadow(direction=45, color=#000000); width:100%">Word Filter 2.0</span></td></tr></table>
<!--BEGIN FORM-->
<table><tr><td>
<font face="verdana,arial,helvetica" size="-1">
<form name="form1" method="get" action="" onSubmit="return wordFilter("form1",["name","email","subject","message"]);">
<table>
<tr><td>Name :</td><td><input type="text" name="name" class="ip"></td></tr>
<tr><td>E-mail :</td><td><input type="text" name="email" class="ip"></td></tr>
<tr><td>Subject :</td><td><input type="text" name="subject" class="ip"></td></tr>
<tr><td>Message</td><td><textarea name="message" rows="5" cols="30"></textarea></td></tr>
</table>
<input type="submit" value="Submit Form" class="btn">
</font>
</form>
</td></tr></table>
<!--END FORM-->
<!--BEGIN CONTENT-->
<table><tr><td>
<font face="verdana,arial,helvetica" size="-1" color="#000000">
This JavaScript is a "Word Filter". It is a type of form validator.
When the user submits some text, the validator will check the text for words that has to be filtered.
<br><br>The words that have to be filtered must be added to the array <font face="courier">swear_words_arr</font>. When the user types the text and hits the submit button, if the text contains any word that is present in the array <font face="courier">swear_words_arr</font>, the form will not be submitted.
<br><br>Place the <code><font size="2"><script></font></code> in the <code><font size="2"><HEAD></font></code> section of your page.
<br><br><b>In this version, you can validate multiple form fields. View the source and see the section marked </b><code><font size="2"><--BEGIN FORM--></font></code>
<br><br>The script can be used for validation of swear words etc.
</td></tr></table>
<!--END CONTENT-->
<table style="width:100%; background:#0066CC"><tr><td><span class="link">© 2002 Premshree Pillai. </td></tr></table>
</td></tr></table>
<table cellspacing="0" cellpadding="0" bgcolor="#0066CC" align="center" width="448"><tr><td></td></tr></table>
<table cellspacing="0" cellpadding="0" bgcolor="#0066CC" align="center" width="446"><tr><td></td></tr></table>
</body>
</html>
Word Filter Demo
<html>
<head>
<title>Word Filter</title>
<!--BEGIN WORD FILTER JAVASCRIPT-->
<script language="JavaScript1.2">
// Word Filter
// (c) 2002 Premshree Pillai
// Created : 23 June 2002
// http://www.qiksearch.ru
// http://javascript.qik.cjb.net
// E-mail : qiksearch@rediffmail.ru
var swear_words_arr=new Array("fuck","bloody","war","terror");
var swear_alert_arr=new Array;
var swear_alert_count=0;
function reset_alert_count()
{
swear_alert_count=0;
}
function validate_user_text()
{
reset_alert_count();
var compare_text=document.form1.user_text.value;
for(var i=0; i<swear_words_arr.length; i++)
{
for(var j=0; j<(compare_text.length); j++)
{
if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase())
{
swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
swear_alert_count++;
}
}
}
var alert_text="";
for(var k=1; k<=swear_alert_count; k++)
{
alert_text+="\n" + "(" + k + ") " + swear_alert_arr[k-1];
}
if(swear_alert_count>0)
{
alert("The form cannot be submitted.\nThe following illegal words were found:\n_______________________________\n" + alert_text + "\n_______________________________");
document.form1.user_text.select();
}
else
{
document.form1.submit();
}
}
function select_area()
{
document.form1.user_text.select();
}
window.onload=reset_alert_count;
</script>
<!--BEGIN WORD FILTER JAVASCRIPT-->
</head>
<body bgcolor="#FFFFFF">
<!--BEGIN FORM-->
<table cellpadding="10" style="border:2 solid #FF9900" width="200" align="center"><tr><td>
<form name="form1" method="post" action="post.cgi">
<center><font face="Times New Roman" size="6pt" color="#606060"><b><i>Word Filter</i></b></font></center>
<table><tr><td></td></tr></table>
<textarea rows="3" cols="40" name="user_text" style="border:2 solid #808080; font-family:verdana,arial,helvetica; font-weight:normal; font-size:10pt" onclick="select_area()">Enter your text here...</textarea>
<table><tr><td></td></tr></table>
<center><input type="button" style="background:#EFEFEF; border:2 solid #808080; width:100%; cursor:pointer" value="Submit" onclick="validate_user_text();"></center>
</form>
<font face="verdana,arial,helvetica" size="-1" color="#000000">
This JavaScript is a "Word Filter". It is a type of form validator.
When the user submits some text, the validator will check the text for words that has to be filtered.
<br><br>The words that have to be filtered must be added to the array <font face="courier">swear_words_arr</font>. When the user types the text and hits the submit button, if the text contains any word that is present in the array <font face="courier">swear_words_arr</font>, the form will not be submitted.
<br><br>The script can be used for validation of swear words etc.
<br><br><font size="-2" color="#808080">© 2002 Premshree Pillai.</font>
</font>
</td></tr></table>
<!--END FORM-->
</body>
</html>