JSFiddle - React, Tailwind, and code Playground

Force Numeric Input

by bitstarr

HTML

<input class="numeric" value="" />

JavaScript

jQuery.fn.forceNumericOnly = function(){
        return this.each(function(){
            $(this).bind('keyup focusout', function(e){
                this.value = this.value.replace(/[^0-9\.]/g,'');
            });
                
        });
    };
    
$('input.numeric').forceNumericOnly();