0

Please consider this Fiddle.

I want to filter inputs on my input that user can just enter numbers. It works when I pressed alphabet keys and shift+alphabet keys(nothing added to input). But it doesn't work when shift+1 (!) and shift+2(@) and ... . Where is my mistake and how can I solve this problem?

Arian
  • 12,793
  • 66
  • 176
  • 300
  • Consider changing the input type to `number` – dotconnor Dec 02 '18 at 06:40
  • Possible duplicate of [How to catch enter keypress on textarea but not shift+enter?](https://stackoverflow.com/questions/6178431/how-to-catch-enter-keypress-on-textarea-but-not-shiftenter) – Khushali Dec 02 '18 at 06:48

1 Answers1

1

You can block out the input when the shift key is pressed by checking for e.shiftKey.

I added the following clause inside your keyDown listener method:

if (e.shiftKey) {
    alert("true");
}

and saw that it was being called when pressing the shift key.

There is also this SO topic, which can be helpful.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52