JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="i">
JavaScript
document.getElementById("i").onkeydown = function(e){
if((e.which >=48 && e.which <=57) // цифры
|| (e.which >=96 && e.which <=105) // num lock
|| e.which==8 // backspace
|| (e.which >=37 && e.which <=40) // стрелки
|| e.which==46) // delete
{
return true;
} else {
return false;
}
}