JSFiddle - React, Tailwind, and code Playground
HTML
<input type='text'></input>
JavaScript
$('input').on('input', function(event) {
const numericRegExp = /^\d+$/;
const regExpObj = new RegExp(numericRegExp);
console.log(event.key)
if (!regExpObj.test(event.key) || event.keyCode === 32) {
event.preventDefault();
}
});