Categories
JavaScript Answers

How to check for keyCode values for numeric keypad with JavaScript?

Spread the love

Sometimes, we want to check for keyCode values for numeric keypad with JavaScript.

In this article, we’ll look at how to check for keyCode values for numeric keypad with JavaScript.

How to check for keyCode values for numeric keypad with JavaScript?

To check for keyCode values for numeric keypad with JavaScript, we can check for the key code ranges for numeric keys.

For instance, we write

if (
  (e.keyCode >= 48 && e.keyCode <= 57) ||
  (e.keyCode >= 96 && e.keyCode <= 105)
) {
  // ...
}

to check for presses for the digit keys.

The digit keys on the top of the keyboard has key code range 48 to 57.

The digit keys on the numeric keypad has key code range 96 and 105.

Conclusion

To check for keyCode values for numeric keypad with JavaScript, we can check for the key code ranges for numeric keys.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.