Words Validation with Javascript
Words Validation with Javascript
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("dog","badword-2","badword-3"); function badwords(txt) { var alert_arr=new Array; var alert_count=0; var compare_text=txt; var total = bad_words_array.length; var matches = 0; for( var i = 0; i < total; i++ ) { if(compare_text.indexOf(bad_words_array[i]) > -1) { var message=1; return message; break; } } }
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>
I have fixed couple of bugs in this script. This is working like a charm now.
Words Validation with Javascript,Incoming search terms:
- yii framework interview questions (13)
- javascript form validation that alert when there are bad words entered (11)
- word validation in javascript (7)
- WordsValidationwithJavascript-BestOnlineSolutionForWebsiteScriptsAndTutorials (3)
- badwords txt (3)
- how to validate button restrict to special characters in jquery (2)
- words javascript (1)
- JS event close form (1)
- javascript/ (1)
- javascript to block words (1)
- javascript on exit textbox (1)
- keypress jquery validation for alphanumeric characters (1)
- page bad word filter javascript (1)
- Please wait JavaScript (1)
- using asp net remove badwords from the textbox (1)
- validate a word in javascript (1)
- validate word javascript (1)
- validation for balanced quote in javascript (1)
- two column text box word validation in javascript (1)
- javascript code for preventing bad words to be submitted (1)
- asp net block curse word (1)
- asp net curse-word input filter (1)
- bad word filter javascrip (1)
- bad word filter javascript (1)
- bad word validation using javascript in asp net (1)
- bad words validation in javascripts (1)
- bad words validation in js (1)
- Block word in JavaScript (1)
- block word validation jquery (1)
- how to avoid to type inappropriate words in javascript (1)
- how to stop bad words posting in javascript (1)
- how to validate textbox special word type in javascript (1)
- inappropriate words validation with jquery (1)
- javascript bad words form validation (1)
- javascript calculate distinct words (1)
- 2 word validation in javascript (1)
the code not working
Hello Lucy,
Thanks for bringing this up, The issue has been fixed. Code is working fine now.