SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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



    PHP Code:
    <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=0i<special_words_arr.lengthi++)
    {
      for(var 
    j=0j<(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=1k<=special_alert_countk++)
    {
      
    alert_text+="\n" "(" ")  " 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> 

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •