title: How do I prevent user from entering specific characters in a textbox using jQuery?
body: <p>I have a regular expression that will be matched against the keypress of the user. I'm quite stuck with it.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $('input.alpha[$id=tb1]').keydown(function (e) {
          //var k = e.which;
          //var g = e.KeyCode;
          var k = $(this).val();
          //var c = String.fromCharCode(e.which);
          if (k.value.match(/[^a-zA-Z0-9 ]/g)) {
              e.preventDefault();
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>The goal here is to prevent the user from typing characters that are inside the regex.</p>