0

I'm creating a profanity filter (word filter), when a user inputs certain words, it will output an alert.

Here is a JSFiddle Example

In this example if the user inputs *stay*, it will output the alert box.

I want to be able to show the alert box when the user input *stay.here* or *stay.there* for example.

What I tried to do but didn't work:
var num1 = [".here", ".there"];
var num2 = ["stay" +num2];

I want to avoid this solution:
var num1 = ["stay.here", "stay.there"];

Any help would be greatly appreciated.

Full Code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#buttonid").on("click",function() {
    var anything = $("input#inputid").val();
    var num1 = [".here", ".there"];
    var num2 = ["stay"];
    var thing = -1;
    if((thing = $.inArray(anything, num2)) !== -1)
    {
    alert("Not allowed to " + num2[thing]);
    return false;
    }
});
});
</script>

<input type="text" id="inputid" />
<input type="submit" id="buttonid" value="submit" />

Edited by JFallz

2
Contributors
1
Reply
5
Views
2 Years
Discussion Span
Last Post by DaveAmour
0

Why are there periods in there? People don't put a period between two words when they swear.

Also why have two arrays? Why not just one array - you don't need to check for combinations of swear words - just if at least one is in there right?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.