"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, July 16, 2010

word filtering or restrict spam words input through javascript

Hi friendz,
 2day i'm showing u a simple JavaScript magic.Some times in our website user filled are filling by some abuse words.we can overcome this by filtering the words by javascript.


Demo



Functioning

i'm saving all the spam word in an array and  on onkey() sending the word to function and their i split the word from the array and match with word.

code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">

function spamcheck(what,spamstr)
{
    var a=document.getElementById(what).value;
    a = a.toUpperCase();
    var temp = new Array();
    temp = spamstr.split(':');
    document.getElementById("spamkey").innerHTML="";
    var index=0;
    while(index<temp.length)
    {
        if(a.search(temp[index]) > -1)
        {
            document.getElementById("spamkey").innerHTML="Remove the spam keyword "+temp[index]+" from your content";
            return false;
        }
        index++;   
    }
    return true;
}

</script>
</head>
<body>
<textarea name="message" id="message" style="width:250px; height:100px;" onkeyup="spamcheck('message','TO CLAIM YOUR PRIZE:FUCK:LUCKY DRAW:MOBILE DRAW:YOUR MOBILE WON:GAY:LOTTERY:ONGOING COCA COLA:DRAW :MOBILAZATION:BT9003@HOTMAIL.COM:DOLLARS:USD:WORLD AID:AND CLAIM:CLAIM YOUR WINNING AMOUNT:POUNDS:YOU HAVE WON:GBP:SEND YOUR NAME AND YOUR ADDRESS:ONGOING SHELL:CEL   L DRAW:CASH OF :CELL DRAW:HAS BEEN AWARDED:CO.UK: UK : EURO:PUOND:FOR CLARIFICATION AND CLAIM: INTL DRAW :WINNING AMOUNT:WINNING:.CO.UK:BRITISH: POUN:UK CHEVRON:UKCHEVRON:DRAW,:YOUR WINNING:DRAW.:£:WRDPRMTN148:FROM SHELL:FRM SHELL:EIM_DRAW:COCACOLA:VIA E-MAIL:HAVE WON: PRIZE :CONTACT DR: WON :URGENTLY FOR DECLARATION: SPA :MARCOPOLO:UR GOODS: GOODS : SHIP :BINGO:LIVETMOBILE:T-MOBILE:LOTE:INTL:LUCKY LOTE:CONSIGNMENT:MOBILE LOTO:G.B P:CLAIM:(ORANGE):INT’L:Dr. PAUL:GB:ORANGE TELECOM:OIL&GAS COMPANY UK:T-MOBELI:ORANGE: LUCKY :YOU HAVE GOT:WORLD BANK:HENIKEN:FOR MORE INFORMATION:HEINEK:HOTMAIL:YOU HAVE BEEN APPROVED:LYNDA:JACKPORT:YOU HAVE BEEN AWARDED:WWW.ATCR.BIZ:SPDCUK');" ></textarea>

<div id="spamkey" style="font-size:13xp; font-weight:bold; color:#FF0000;"></div>
</body>
</html>




Have a nice day... 'N happy Coding :)

No comments: