JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="number" onkeypress="return isNumber(event);" />

JavaScript

function isNumber(evt) {
    var theEvent = evt || window.event;
    var theVal = theEvent.target.value;
    var key = theEvent.keyCode || theEvent.which;

    key = String.fromCharCode(key);

    if (key.length == 0) return;

        if (theEvent.preventDefault) theEvent.preventDefault();
        return false;
}