The best way to force the use of a number composed of digits only:
<input type="number" onkeydown="javascript: return ['Backspace','Delete','ArrowLeft','ArrowRight'].includes(event.code) ? true : !isNaN(Number(event.key)) && event.code!=='Space'" />
this avoids 'e', '-', '+', '.' ... all characters that are not numbers !
To allow number keys only, convert to number with Number
function. If this is not a number, the result is NaN :
isNaN(Number(event.key))
but accept Backspace, Delete, Arrow left, Arrow right :
['Backspace','Delete','ArrowLeft','ArrowRight'].includes(event.code)
This is for Firefox which allows spaces :
event.code!=='Space'