This Tutorial Has Been Viewed 9,823 Times.
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
You will also be interested in ,
- Extracting URL parameters with Javascript
- Limit Textarea Characters Using Javascript
- DOM elements dynamically using our JAVASCRIPT
- Replacing images with time intervals using jquery
- Visitor counter using cookies and javascript
- Simple div slideshow using jquery
- Write data to a page using javascript
- Replace all non alphanumeric characters using javascript
- Fade in Fade out effect using simple jquery
- Calculate the webpage load time using javascript
Categories: JavaScripts, scripts