Click to See Complete Forum and Search --> : Profanity Verifing
californiasteve
07-25-2003, 11:29 PM
I'm trying to figure up a way to check a form input boxes for profanity and if it is present use the "return" to stop the form from submitting. I can't figure out if I want to use "indexOf" or use the match method. I seem to be on the right path with my thinking but can't figure out to multiple words for the indexOf to search for. Don't really have any code that works I can post. Steve
xataku_nakusute
07-25-2003, 11:40 PM
to start you off, you can try:
<script type="text/javascript">
function pcheck()
{
field = document.forms[0].inputname.value;
if(field=="profane word" && field=="another profane word" && field=="do as many of these as you want"){
field="";
}
else
{
}
}
</script>
<form>
<input name="inputname" onkeyup="pcheck()">
</form>
it might work, i havent tested it though
Exuro
07-26-2003, 12:27 AM
If I were you I'd use a regular expression. That way you don't have to go through and do str.indexOf(word)==-1 a whole bunch of times. Instead you just use something like this:
<script type="text/javascript">
<!--
function check(str) {
words = /(word1|word2|word3|word4|ect)/
if (words.test(str)) {
alert(RegExp.lastMatch)
}
}
//-->
</script>
By using a regular expression you can also set it so that something like "Hello" is not considered profane, but then it starts getting complicated...
californiasteve
07-27-2003, 12:55 PM
Thanks to both of you I'm getting the hang of this now.Thanks to both of you. Steve