Word filter by lengh of the word?

i have a word filter script but the problem is that it can be overpassed easy what i want is to count exacly the letter of the word cz for example the word cheer is banned but not the word cheerleader but the filter validates cheerleader as if it was cheer how can i get to count the words exacly

<HTML>
<HEAD>
<TITLE>Test Input </TITLE>


<!--BEGIN WORD FILTER JAVASCRIPT-->
<script language="JavaScript1.2">


var special_words_arr=new Array("cheer","bloody","war","terror");
var special_alert_arr=new Array;
var special_alert_count=0;

function reset_alert_count()
{
special_alert_count=0;
}

function validate_user_text()
{
reset_alert_count();
var compare_text=document.form1.user_text.value;
for(var i=0; i<special_words_arr.length; i++)
{
  for(var j=0; j<(compare_text.length); j++)
  {
   if(special_words_arr[i]==compare_text.substring(j,(j+special_words_arr[i].length)).toLowerCase())
   {
    special_alert_arr[special_alert_count]=compare_text.substring(j,(j+special_words_arr[i].length));
    special_alert_count++;
   }
  }
}
var alert_text="";
for(var k=1; k<=special_alert_count; k++)
{
  alert_text+="\
" + "(" + k + ")  " + special_alert_arr[k-1];
}
if(special_alert_count>0)
{
  alert(" these words are not valide cheer,bloody,war,terror");
  document.form1.user_text.select();
}
else
{
   alert("well done no special words used");
}
}

function select_area()
{
document.form1.user_text.select();
}

window.onload=reset_alert_count;

</script>
<!--END WORD FILTER JAVASCRIPT-->

</HEAD>
<BODY>

<form name="form1" method="post" action="your_post_address.asp">
<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></form>

</BODY>
</HTML>

Use .split(" ") to break the user input into an array of words. Loop through this array and compare to your banned words array.

If there is a user word that exists in the banned words array then you can increment special_alert_count. :slight_smile: