JSFiddle - React, Tailwind, and code Playground

HTML

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

JavaScript

$('#test').on('keypress', function(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode;
    return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});

$('#test').on('focusout', function() {
    var value = $(this).val();
    
    $(this).val(value.replace(/[^0-9]/g, ''));
});