Mega Code Archive

 
Categories / JavaScript DHTML / Page Components
 

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.com // http://javascript.qik.cjb.net // E-mail : qiksearch@rediffmail.com 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">&lt;script&gt;</font></code> in the <code><font size="2">&lt;HEAD&gt;</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">&lt;--BEGIN FORM--&gt;</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">&copy; 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>