Giovanni, You need to use the keypress event if you truly want to know which character was pressed.
However, IE6 doesn't register the keypress event for certain non-printable characters (like the backspace, the arrow keys, etc.) So, for IE6 you need to capture those characters either on keydown (which I prefer) or keyup and then call your event handler function (onlyNumbers) for when those keys are pressed. -Dan >-----Original Message----- >From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On >Behalf Of Giovanni Battista Lenoci >Sent: Thursday, May 15, 2008 10:34 AM >To: jQuery (English) >Subject: [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