Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop abusive words using jquery or javascript

I want to filter some word(sex etc) using regex, but some time people use that words like that (b a d)(b.a.d)(b/a/d) and so on how to stop these kind of words using regex.

That is only one word I need to filter all that kind of words I have write that code but its not work perfectly

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script src="jquery-1.8.3.js"></script>
<title></title>
<meta name="" content="">
</head>
<body>

</body>

<script>
  $(document).ready(function(){
    var a=['bad','worse'];
    for(var i=0; i<a.length; i++){

          var re = new RegExp(a[i],"g");
          var str = "bad words here"; 
          var res = str.match(re);

          if(res.length>0){
                alert(res);
                break;
          }
     }
   });  
 </script>
  </html>
like image 205
Sheraz Avatar asked Sep 26 '22 13:09

Sheraz


1 Answers

Try this:

return "";

This is the only way that you will ever stop people from using words you don't like: don't allow them to use any words at all.

Even if you detect certain words, you will have many problems with it, many of which were given to you in a comment on your question. Swapping characters like in @$$ is all too common, and the nerdier people will know about the Cyrillic characters that look identical to Latin characters - try detecting sеx with your regex!

It is infinitely more efficient to take a more social approach to this problem. If your community is disinclined to post such words, then there's no need to worry about it. If you moderate the rare posts that contain such words, then the perpetrator won't be able to do it again and others may think twice before following in their footsteps. I have never had any word filters on my user-submitted content, and while we do get the occasional potty-mouth, they're always super-fast to deal with instead of the many hours that would go into trying to stop them in the first place.

like image 132
Niet the Dark Absol Avatar answered Nov 03 '22 23:11

Niet the Dark Absol