JSFiddle - React, Tailwind, and code Playground
HTML
<input class="input" maxlength="1" id="text" type="text" autocomplete="off" />
JavaScript
var text = document.getElementById('text');
text.onkeypress = checkInput;
text.onpaste = checkInput;
function checkInput(e) {
var e = e || event,
char = e.type == 'keypress'
? String.fromCharCode(e.keyCode || e.which)
: (e.clipboardData || window.clipboardData).getData('Text');
if (/[^\d]/gi.test(char)) {
return false;
}
}