JSFiddle - React, Tailwind, and code Playground

by ult_combo

HTML

<input onkeypress="return isNumberKey(event)" />

JavaScript

function isNumberKey(evt)
  {
    var e = evt || window.event; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;                        
    if (charCode > 31 && (charCode < 47 || charCode > 57))
    return false;
    if (e.shiftKey) return false;
    return true;
 }