JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input type="text" name="amount" id="sg-amount" placeholder="0.00" />
</form>
JavaScript
$('#sg-amount').on('change click keyup input paste', (function(event) {
$(this).val(function(index, value) {
return value.replace(/(?!\.)\D/g, "").replace(/(?:\..*)\./g, "").replace(/\.(\d\d)\d?$/, '.$1').replace(/\B(?=(\d{3})+(?!\d))/g, ",");
});
}));