javascript check from input if any values are in array of forbidden words <p>I'm having trouble figuring out how to do this. I'm using jQuery and I know the inArray function but I'm stuck. When the user inserts some values in an input field, I want to check if any of the words entered are in an array...if they are then to remove them. Here's what I have:</p> <pre><code>&lt;input type="text" id="search"/&gt; $("#search").bind('enterKey', function(e){ var search = $('#search').val(); var check = ['on', 'a', 'the', 'of', 'in', 'if', 'an']; var id = $.inArray(check, search); if (id !== -1){ alert ("in array"); }else{ alert ("not in array"); } }); $('#search').keyup(function(e){ if(e.keyCode == 13){ $(this).trigger("enterKey"); } }); </code></pre> <p><a href="http://jsfiddle.net/F4ZfD/2/" rel="nofollow">Fiddle</a></p> <p>I'm sure my if statement is wrong...please help me out!</p>