JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" />
CSS
body { margin: 50px; }
JavaScript
$j = jQuery.noConflict();
$j(function() {
$j("input").keypress(function(e) {
var val = $j(this).val();
var regex = /^(\+|-)?(\d*\.?\d*)$/;
if (regex.test(val + String.fromCharCode(e.charCode))) {
return true;
}
return false;
});
});