JSFiddle - React, Tailwind, and code Playground
by therichpost
HTML
<input class="left" id="sign-number" name="sign-number" type="text" placeholder="Number?" onkeypress="validate_only_digits(event);" tabindex="8">
JavaScript
function validate_only_digits(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
var keychar = String.fromCharCode(key);
var keycheck = /[0-9 ]|\-/;
if (!(key == 8 || key == 9 || key == 27 || key == 46 || key == 37 || key == 39 || key == 40 ||key == 41 || key !=46)) {
if (!keycheck.test(keychar)) {
theEvent.returnValue = false;
if (theEvent.preventDefault)
theEvent.preventDefault();
}
}
}