top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to block inappropriate content using JavaScript validation, any sample code would be useful?

+1 vote
497 views
How to block inappropriate content using JavaScript validation, any sample code would be useful?
posted Apr 7, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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.

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>
answer Apr 18, 2016 by Manikandan J
Similar Questions
+3 votes

My form is somewhat like this:-

 <form id="form1" method="post" name="form1">
 //...fields like firstname, email......
 <button type="submit" id="submit" name="submit" onclick="validate(this)">SUBMIT</button>
 < /form>

The javascript validate function:-

function validate(ref)
{
    if(document.form1.firstname.value=="")
    {
            window.alert("First Name Cannot be Blank");
            return;
    }

    // validating other fields like email... If any field is invalid return 
    document.form1.action="response"
    document.form1.submit()
} 

Now what the problem is suppose I left the firstname field blank and click submit button then windows alerts that firstname field is mandatory....and as soon as I click the OK button in alert form the form is posted...

Now question is that I assign the action attribute after validating all the fields and if any one is invalid the function returns in which case action attribute of the form is not assigned then how the form is submitted.
The form should have been submitted after all the validation tests will have been successful and controls would have reached document.form1.submit(). And what is the solution for this.

I am using Python Flask and rendering template using jinja2.

...