XTGeminiman
08-15-2005, 04:08 AM
Hey guys, I want to make this script display a list of the bad words that come up in the alert box rather than simply displaying how many bad words there are. So if the word bloody is typed I want it to show that in the alert box along with any other curse words. Can someone help me out?
<script type="text/javascript">
badWords = ['sod you', 'bollocks', 'bloody'];
function check (f) {
if (!/\S/.test (f.elements.message.value)) {alert ('Please, a message is required.'); return false};
if (!/\S/.test (f.elements.title.value)) {alert ('Please, a message is required.'); return false};
var count = 0, i = 0, pattern, word;
while (word = badWords[i++]) {
pattern = new RegExp ('\\b' + word + '\\b', 'gi');
while (pattern.test(f.elements.message.value)) {count++}
}
if (count) {
alert ('Shame on you. You have used bad words ' + count + ' times.')
return false;
}
}
</script>
<script type="text/javascript">
badWords = ['sod you', 'bollocks', 'bloody'];
function check (f) {
if (!/\S/.test (f.elements.message.value)) {alert ('Please, a message is required.'); return false};
if (!/\S/.test (f.elements.title.value)) {alert ('Please, a message is required.'); return false};
var count = 0, i = 0, pattern, word;
while (word = badWords[i++]) {
pattern = new RegExp ('\\b' + word + '\\b', 'gi');
while (pattern.test(f.elements.message.value)) {count++}
}
if (count) {
alert ('Shame on you. You have used bad words ' + count + ' times.')
return false;
}
}
</script>