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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *