Nullify while typing non allowed chars
<p>I need to add a control to a text input field in order that it will allow only hashtags  on it, one per time:</p>

<pre><code>in the form: valid_hash = /#([a-zA-Z_0-9]+)/gim;


&lt;input type="text" id="add_by_hand"&gt;
</code></pre>

<p>so far: </p>

<pre><code>$(function() {
  var txt = $("#add_by_hand");
  var func = function(e) {
    if(e.keyCode != "37" &amp;&amp; e.keyCode != "38" &amp;&amp; e.keyCode != "39" &amp;&amp; e.keyCode != "40"){
        txt.val(txt.val().replace(/\s/g, ''));
    }
  }
  txt.keyup(func).blur(func);
});
</code></pre>

<p>this is okay only to avoid spaces (thus having only one hashtag per time)
but I'd like to validate it in a way that if a character that is not allowed by the valid_hash  var it's automatically removed. any help is greatly appreciated.</p>
