JSFiddle - React, Tailwind, and code Playground

by Chuan Shao

HTML

<input type="number" onkeypress="myFunc(event)">

JavaScript

window.myFunc = function(event) {
  if(!(event.charCode >= 48 && event.charCode <= 57) && event.charCode !== 46) {
    event.preventDefault();
  }
};