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.