Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Banned
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation anyone no a a script/site ect for a filter

    anyone got a site/script for a bad word filter

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Here is what I use:
    function smutEnginesubject() {
    var smut="*#*?*&*%*!*#*?*&*%*!*#*?*&*%*!";
    var badnum=0;

    cmp="bad words go in here with a space between and a space at the end ";

    txt=document.adinputform.AdSubject.value;
    for (var i=0;i<62;i++) { #replace 62 by number of bad words
    pos=cmp.indexOf(" ");
    wrd=cmp.substring(0,pos);
    wrdl=wrd.length;
    cmp=cmp.substring(pos+1,cmp.length);
    while (txt.indexOf(wrd)>-1) {
    pos=txt.indexOf(wrd);
    txt=txt.substring(0,pos)+smut.substring(0,wrdl)+txt.substring((pos+wrdl),txt.length);
    badnum=badnum+1;
    }
    }
    document.adinputform.AdSubject.value=txt;
    if (badnum>0) {
    alert ("Your ad heading contains " +badnum +" word\(s\) which are not permitted.\n\nYou may wish to change the heading to make it more acceptable.");
    document.adinputform.AdSubject.focus();
    return false;
    }

    var xflag=0;
    var badchars="/\*-#";
    for (var x=0;x < txt.length;x++) {
    if (badchars.indexOf(txt.charAt(x))!=-1) {xflag++}
    }
    if (xflag>3) {
    document.adinputform.reset();
    alert ("No thanks, "+truename+"! We don\'t want that sort of ad on our board! ");
    blocked=1;
    }
    }

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Client side filtering can be easily circumvented. Server side scripting should be used for a feature like that.

    Still your script is very inefficient:
    First, your function is tied to a particular form field, which makes it non-reusable. Much better approach is to make function take the string to be filtered as an arguement and return the filtered string (who really cares how many bad words have beed found).
    Second, your string manipulation can be done much better with the use of regular expressions (even if you insist on using the list of bad words as a space separated string instead of an array):

    Code:
    function filterBadWords(instring)
      { var badwords = "your bad words here";
        bwarray = badwords.split(' ');
        for(var i=0; i<bwarray.length; i++)
          { re = new RegExp(bwarray[i],'ig');
            // replace string can also be an arguement
            instring.replace(re,'####');
         }
        return instring;
      }
    Last edited by Vladdy; 02-04-2004 at 07:42 PM.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #4
    Banned
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks but....

    theres a problem its not working

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Thank you Vladdy. I take on board what you say. However, although inefficient the thing still works.

    I guess that to you as a professional efficiency is important if your scripts are being accessed many times a day. Mine is accessed perhaps twice a week. But I am keen to learn and will make the alterations you suggest.


    Netpets - as it stands the script is only an example. You will
    need to make alterations to the form name and field name.

    Also, you must delete the #replace 62 by whatever comment.

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I took Vladdy suggestion and altered it, I took the liberty to test it with some bad words , this script checks up on words opposed to vladdys initial one that checked up on letter constallations. the splitter is * and remember a space on eash side of the bad word in the bad word sting, the alert in the start is just a test.
    Code:
     
    <script>
    alert(filterBadWords('This is a bad word replacer not wordperfect'));
    function filterBadWords(instring)
    {
      var badwords = " bad * word * gimp ";
      bwarray = badwords.split('*');
      for(var i=0; i<bwarray.length; i++)
      {  
    	  re = new RegExp(bwarray[i],'ig');
        // replace string can also be an arguement
        instring=instring.replace(re,' #### ');
      }
      return instring;
    }  
    </script>
    Last edited by Garadon; 02-05-2004 at 10:38 AM.

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Garadon, the space is only one of the possible word boundaries. Other can include period, comma, new line, etc.
    If you prefer to check on complete words, constuct the regular expression with \b:
    re = new RegExp('\\b' + bwarray[i] + '\\b','ig');
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ofcourse ur rigth lol , but why even use a badword filter its a bad idea to start with. Freedom of speech and all, and to think how many thousands of words that could be considered bad. In short its a complete waste of time if you ask me.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    If you prefer to check on complete words, constuct the regular expression with \b:
    re = new RegExp('\\b' + bwarray[i] + '\\b','ig');


    Well, yes.

    Otherwise people in Penistone and Scunthorpe may feel discriminated against and sue you for zillions of dollars for emotional distress etc.


  •  

    Posting Permissions

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