title: convert HTML5 Regex pattern to javascript Regex
body: <p>For an input field with a regex pattern:</p>
  
  <p><code>&lt;input type="text" maxlength="4" inputmode='numeric' pattern="\d*"&gt;</code></p>
  
  <p>I would like to use <em>javascript</em> to validate the input, by parsing the <code>pattern</code> attribute in some way like this (<strong>which doesn't work</strong>):</p>
  
  <pre><code>$('input').on('keypress', function(e){
      var regex = this.pattern,
          valid = eval(regex).test( e.charCode );
  
      if( !valid )
          return false;
  });
  </code></pre>
  
  <p>I know the Regex in the pattern is different than the one JS uses, but I need some way to convert any Regex in a way this method could work, to allow the typing of only the chars allowed by the pattern.</p>