title: Checking regex expression on keypress
body: <p>I would like to create my own plugin (without use any external libraries - it's for learning purpose) to validate text typed by user dynamically in regex test function.</p>
  
  <p>In example I have regex pattern: </p>
  
  <blockquote>
    <p>^.{2}$</p>
  </blockquote>
  
  <p>And javascript function</p>
  
  <pre><code>$('#textbox').bind("keypress", function (event) {
      var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
      if (!regex.test(key)) {
          event.preventDefault();
          return false;
      }
  });
  </code></pre>
  
  <p>Now, I want to type two dots into textbox, but after first keypress is fired, one dot doesn't match to the pattern and nothing happens because event is prevented.</p>
  
  <p>My question: Is it possible to check if currently typed text matches with regex pattern? </p>