[jQuery] Filtering charachter input with jquery/javascript
Hi, I'm having a problem filtering keyboard input in a text field.
Here is the page with the test:
http://lab.gianiaz.com/jquery/filter_input/
I use this function to catch the key pressed by the user:
function onlyNumbers(e) {
key = e.keyCode;
if(debug) log("onlyNumbers\nkey_code:"+key);
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) ||
(key==27) ) return true;
keychar = String.fromCharCode(key);
if(debug) log("keychar:"+keychar);
// numbers
if((("0123456789.,").indexOf(keychar) > -1)) {
if(debug) log('OK');
return true;
}
if(debug) log('KO');
return false;
}
But If I press a number it works, when I press the "dot" or the
"comma" key I receive this:
onlyNumbers key_code:190
keychar:¾
KO
onlyNumbers key_code:188
keychar:¼
KO
Can you help me understand why it doensn't works?
Bye