facebook twitter youtube
in JavaScripts - 22 May, 2011, This Tutorial Has Been Viewed 16,523 Times.
by admin - no comments
Words Validation with Javascript
VN:F [1.9.22_1171]
Rating: 7.7/10 (12 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.22_1171]
Rating: 7.7/10 (12 votes cast)
Words Validation with Javascript, 7.7 out of 10 based on 12 ratings

Incoming search terms:




coded by nessus

Leave a Reply

Close
Please support the site
By clicking any of these buttons you help our site to get better