JSFiddle - React, Tailwind, and code Playground

by TheDiamondDoge

HTML

<input id="input" type="text">

JavaScript

let input = document.getElementById("input");
input.addEventListener("input", function(e) {
  e.target.value = onInput(e);
});

onInput = (event) => {
  let str = "" + event.target.value;
  return str.replace(/[^0-9]/gm, "");
}