»
EnglishFrenchVietnamese

Print - Word Filter script - JavaScriptBank.com

Full version: jsB@nk » Utility » Counter-Limitation » Word Filter script
URL: https://www.javascriptbank.com/word-filter-script.html

Word Filter script © JavaScriptBank.comThis form validator filters pre-selected words in a textbox. When the user submits text, the validator will check the words against the list of banned words.

Full version: jsB@nk » Utility » Counter-Limitation » Word Filter script
URL: https://www.javascriptbank.com/word-filter-script.html



JavaScript
<SCRIPT LANGUAGE="JavaScript"><!-- Begin// by Premshree Pillai , premshree@hotmail.com , http://www.qiksearch.com/// Enter the words to be filtered in the line below:var swear_words_arr=new Array("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;//  End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="form1"><textarea rows="3" cols="40" name="user_text" style="border:2px solid #808080; font-family:verdana,arial,helvetica; font-weight:normal; font-size:10pt" onclick="select_area()">Enter your text here...</textarea><br><br><input type="button" style="background:#EFEFEF; border:2px solid #808080; width:25%; cursor:pointer" value="Submit" onclick="validate_user_text();"></form><p>Try entering the words &quot;bloody&quot;, &quot;war&quot;, or &quot;terror&quot; in the text box above.</p><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->