...

View Full Version : alert for prohibited word



joonstar
10-30-2004, 01:52 AM
<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

jamescover
10-30-2004, 02:22 AM
<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:


<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

joonstar
10-30-2004, 02:58 AM
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

SpiritualStorms
10-30-2004, 03:08 AM
I would also suggest an array for a list of terms to check for. For example,



// 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.

Philip M
10-30-2004, 08:29 AM
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.



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;
}
}

SpiritualStorms
10-31-2004, 09:48 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum