Created
March 28, 2019 11:20
-
-
Save srph/d3d2e8a526aea9f790fdfc8192d5ee04 to your computer and use it in GitHub Desktop.
JS: Check if the pressed key (evt.keyCode) is a numeric key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NUMERIC_0 = 48 | |
const NUMERIC_9 = 57 | |
/** | |
* Check if the pressed key (evt.keyCode) is a numeric key | |
*/ | |
export default function isNumericKeyCode(key: number): boolean { | |
return key >= NUMERIC_0 && key <= NUMERIC_9 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment