If you are making a system where peoples come and give there reviews or accept content from public post, there is always some bad peoples write bad words and you have to manually manage these posts. Now with this article you will be able to manage inappropriate words and restrict peoples to write on website. Its a simple and easy to implement program hope you enjoy it.
create Bad word validation first create inappropriate.js File.
var words_array=new Array("bad","hate","wrong");
function badwords(txt)
{
var arr=new Array;
var count=0;
var text=txt;
for(var i=0; i<words_array.length; i++)
{
for(var j=0; j<(text.length); j++)
{
if(words_array[i]==text.substring(j,(j+words_array[i].length)).toLowerCase())
{
count++;
}
}
}
return count;
}
Javascript and HTML code.
<script type="text/javascript" src="inappropriate.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 inappropriate words.
Please clean up your message.");
document.form.textbox.focus();
return false;
}
}
</script>
<form action="thankyou.html" method="post"
onsubmit="return Message();" name="form">
<textarea name="textbox"></textarea>
<input type="submit" value=" Send "/>
</form>