******************* Don't use KEYCODE !!!! ******************
The problem with keyCode is to avoid the combined keys with the numbers on top of keyboard, we must add a check on the key "Shift" and "Alt" to avoid special characters such as e @ & " { } ...
A simplest solution is to convert e.key to a number and check if the conversion gives NaN!
let key = Number(e.key)
if (isNaN(key) || e.key === null || e.key === ' ') {
console.log("is not numeric")
}
else {
console.log("is numeric")
}
Be careful if e.key is null or a space, it gives 0 !
Number(5) // => 5
Number('5') // => 5
Number(null) // => 0
Number(' ') // => 0
Number('chars') // => NaN
Number(undefined) // => NaN