0

I tried to restrict input to accept numbers only, it works fine using keyboard numbers but when using (keypad at the right) it failed.

What I tried:

$("#NUMBER").keydown(function (e) {
    return( Boolean(String.fromCharCode(e.keyCode).match(/[0-9]+/g)) );
});

Demo: https://jsfiddle.net/9qwv5t9j/

Edit: I tested answer here:https://stackoverflow.com/a/13196983/3599237 and (Demo: https://jsfiddle.net/9qwv5t9j/3/) but its not working.

Community
  • 1
  • 1
Akam
  • 1,089
  • 16
  • 24
  • Use keypress event instead and btw you should use `event.which` which is normalized in jQuery: https://jsfiddle.net/9qwv5t9j/1/ – A. Wolff Mar 24 '16 at 12:37
  • @A.Wolff: its not working also for my keypad I am confused. – Akam Mar 24 '16 at 12:39
  • It works here, check your verrNum lock key maybe... Or this could be depending your keyboard cultur, i don't know... Because anyway, the event to get the char is keypress, keydown/keyup are used to get the key – A. Wolff Mar 24 '16 at 12:41

0 Answers0