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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert for prohibited word

    Code:
    <form action="action.htm" method="post" >
    	    	
      <input name="title">
      <textarea name="say" rows="10"></textarea>
    			  
      <input type="submit" value=" post "> 
    
    </form>
    I have the above code.
    I like to make an alert saying "FK is prohibited word" if a user enters "FK."


    Thanks in Advnace
    Get my greedy up

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by joonstar
    Code:
    <form action="action.htm" method="post" >
    	    	
      <input name="title">
      <textarea name="say" rows="10"></textarea>
    			  
      <input type="submit" value=" post "> 
    
    </form>
    I have the above code.
    I like to make an alert saying "FK is prohibited word" if a user enters "FK."


    Thanks in Advnace

    Try:

    PHP Code:
    <script type="text/javascript">
    <!--

    function 
    chkFrm(){

    illChar "FK";
    var 
    doc document['oFrm'];

    if(
    doc['say'].value.toUpperCase().indexOf(illChar,0) != -1){
    alert(illChar " is prohibited!");
    return 
    false;
    }
    }

    //-->
    </script>

    <form name="oFrm" onsubmit="return chkFrm();" action="action.htm" method="post">
    <textarea name="say" rows="10" cols="25"></textarea>
    <br />
    <input type="submit" value="Check Form" /> 
    </form> 

    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks James. it works!

    I have another question.

    If I have two words or mult words, for example "FK" and "ST" which are to be prohibited, How can I make it?

    Thanks in Advance
    Last edited by joonstar; 10-30-2004 at 03:03 AM.
    Get my greedy up

  • #4
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would also suggest an array for a list of terms to check for. For example,

    Code:
    // declare, and initialise an array:
    
    var badList=new Array();
    
    //  Now populate the array:
    
    badList[ 0 ]="fk";
    badList[ 1 ]="f*ck";
    badList[ 2 ]="F*ck";
    badList[ 3 ]="Fuuk";
    badList[ 4 ]="F--you";
    
    ...and so on, and on. You may extend the list. 
    
    //  Now for a function:
    function chkFrm(){ 
    
    var doc = document['oFrm']['say']; 
    
    if( doc.value!=-1 ){ 
      for( var indexer=0; indexer <= badList.length; indexer ++  ){
      alert("The word " + badList[ indexer ]  + " is not permited!  Try again.");
       doc.value="";
      }
     }
    else {
      alert("You will need to type something if you want to make a use of me!")
    }
    return false; 
    } 
    
    //--> 
    </script>
    The beauty of an array, as opposed to regular expressions is, that an array allows for a higher level of modification freedom that the other does not have. You see, whenever you use regular expressions, you are stuck with a very, very specific pattern. But what happens when you dont really have a very specific pattern to look for because what you are looking for has an aweful lot of variancies?

    For this reason, its simply more logical, really, to me anyway, to create a mini-database through the existance of an array. Since all arrays are generally a collection, or a group, of some type, it just makes more sense to create an array, and then just have a loop run through the whole array to see if there's any matches. If there is a match, then just specify what the match is, and then give a command to the visitor that the matched term is something that you will not deal with. This is not to say you cant cut corners, and start using toUpperCase() methods, and the what not. But a method like that doesn't really alter the difference between "f*ck" and "f****ck" as far as the actual number of charactors, and the type of charactor are concerned. What this means is that if you were to convert the aforementioned examples to up case, all you would have is, "F*CK", and "F****CK"

    In the end, a mini-database is about the only way to go sometimes. And like i said, you can always increase the list by throwing in new variancies. All of this does not change the rest of your code either.
    Last edited by SpiritualStorms; 10-30-2004 at 03:22 AM.
    LovesWar

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,020
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    This may help you - it works quite well for me. Notice that ucking and ucker
    will catch both the s and f words. Some of my badwords may be filtered out! If not, I do not intend to offend.

    Code:
    function smutEnginesubject() {
    var smut="*#*?*&*%*!*#*?*&*%*!*#*?*&*%*!";
    var badnum=0;
    
    cmp="Nazi nazi FREE obacco igarette sex SEX babes **** shag ucking UCKING ucker UCKER uck UCK cum **** **** sshole rsehole arse ARSE pics pix prick ***** ortgage debt loan lucky wager gaming asino drug lcohol addict ponsor dotco @ XXX $ !! www. http:// .com .co. .net .org .biz .info .ca mailto: pportunity porno iagra damn usiness bugger ******* twat turd ";
    
     txt=document.adinputform.AdSubject.value;
     for (var i=0;i<62;i++) {
      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.  \n\nUnsuitable ads are automatically deleted from our system.");
    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;
    }
    }

  • #6
    Regular Coder
    Join Date
    Dec 2003
    Location
    America
    Posts
    544
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Man does that seem like a monsterous mountain of code, and all, for the mere checking of profanity. I think its too big for a small task. Something better must come a long. I will maintain, that an array, is really your only bet.
    LovesWar


  •  

    Posting Permissions

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