DooDoo
DooDoo

Reputation: 13447

Prevent keyDown event when shift key pressed

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?

Upvotes: 0

Views: 1291

Answers (1)

tomerpacific
tomerpacific

Reputation: 6475

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.

Upvotes: 1

Related Questions