Javascript key board input filtering
<p>Does anyone have a working dynamic javascript input filter that limits text inputs across multiple browsers?  </p>

<p>I've seen multiple examples online, but most of them seem to have flaws or lack multibrowser support.  </p>

<p>My current attempt is posted below, but it's failing for shifted numbers under firefox, and I haven't tried other browsers yet.  </p>

<p>As <a href="http://www.quirksmode.org/js/keys.html" rel="nofollow">http://www.quirksmode.org/js/keys.html</a> shows, it's not an easy problem. </p>

<p>Does anyone have a better solution?</p>

<pre><code>var numb = /[0-9]/;
var lwr = /[a-z]/;
var upr = /[A-Z]/;
var alpha = /a-zA-Z]/; //not checked
var alphaNum = /a-zA-Z0-9/; //not checked

function onKeyPressAcceptValues(e, reg){
 var key = window.event ? e.keyCode : e.which;
 //permit backspace, tab, delete, arrow buttons, (key == 0 for arrow keys)

 alert(key);
 if(key == 8 || key == 9 || key == 46 ||(key&gt;32 &amp;&amp; key &lt;41 ||key == 0)){
  return true;
 }
 var keychar = String.fromCharCode(key);
 return reg.test(keychar);
}

function isNumberKey(parm) {return onKeyPressAcceptValues(parm,numb);}
function isLowerKey(parm) {return onKeyPressAcceptValues(parm,lwr);}
function isUpperKey(parm) {return onKeyPressAcceptValues(parm,upr);}
function isAlphaKey(parm) {return onKeyPressAcceptValues(parm,alpha);}
function isAlphanumKey(parm) {return onKeyPressAcceptValues(parm,alphaNum);}
</code></pre>

<p>It would be used via </p>

<p><code>&lt;input type="text" name="pw[first_name]" size="15" maxlength="15" onkeypress="return isAlphaKey(event)"&gt;</code></p>
