JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<input type="text" value="" onkeypress="return myfunction(event)" />
</div>
JavaScript
function myfunction(e){
var p = new RegExp(/^[0-9]+([.][0-9]+)?$/);
return e.charCode === 0 || p.test(String.fromCharCode(e.charCode));
}