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