0

I am trying to have a input text field which should allow numbers and few special characters like forward slash(/). So I am handling this through key codes from keydown event.

But I am facing a strange issue. As per the ASCII table, the key codes for numbers 0 to 9 is 48 to 57. But if the same numbers pressed from the number pad in keyboard then keyCode gives a different value. The ASCII code for 0 to 9 in num pad starts from 96 to 105. But this range conflicts with small caps alphabets.

So I would like to know is there any way to differentiate if number keys pressed from the regular number keys and from num pad.

  • *"I am trying to have a input text field which should allow numbers and few special characters like forward slash(/). So I am handling this through key codes from keydown event."* Use `keypress` instead. The code you get on `keypress` has been interpreted for you. The code you get from `keydown` is more "raw" and may vary from keyboard layout to keyboard layout (e.g., French keyboards vs. Swiss keyboards vs. American keyboards vs. Chinese keyboards). – T.J. Crowder Jun 02 '15 at 07:09
  • ASCII code for alphabet 'A' to 'Z' starts from '65' to '90' weather it small cap or full cap, ASCII code remain same for both. for ex. ASCII for 'A' and 'a' is 65. – Sutirth Jun 02 '15 at 07:25

0 Answers0