This Tutorial Has Been Viewed 9,823 Times.
VN:F [1.9.20_1166]
Rating: 6.9/10 (9 votes cast)

Hi today i will explain you how to filter out inappropriate words from being updated or send from your website.This is simple javascript.

badwords.js
Contains javascript code. If you want add some more words in bad_words_array

var bad_words_array=new Array("badword-1","badword-2","badword-3");
function badwords(txt)
{
var alert_arr=new Array;
var alert_count=0;
var compare_text=txt;

for(var i=0; i<bad_words_array.length; i++>)
{
for(var j=0; j<(compare_text.length); j++)
{
if(bad_words_array[i]==compare_text. 
substring>(j,(j+bad_words_array[i].length)).toLowerCase>())
{
alert_count++;
}
}
}
return alert_count;
}

index.html
Contains javascript and HTML code. The form calling Message() function.
<script type=">text/javascript" src=">badwords.js"></script>
<script type=">text/javascript">
function Message()
{
var textbox_val=document.form.textbox.value;
if(textbox_val=="")
{
alert("Please enter a message");
return false;
}
bwords=badwords(textbox_val);
if(bwords>0)
{
alert("Your message contains some bad words please remove it.");
document.form.textbox.focus();
return false;
}
}
</script>
<form action="send.php" method="post"
onsubmit="return Message();" name="form">
<textarea name="textbox"></textarea>
<input type="submit" value=" Submit "/>
</form>

Thanks and regard
bALu
VN:F [1.9.20_1166]
Rating: 6.9/10 (9 votes cast)
Words Validation with Javascript, 6.9 out of 10 based on 9 ratings


coded by nessus
Categories: JavaScripts, scripts

Leave a Reply