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" />

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.