JSFiddle - React, Tailwind, and code Playground

HTML

<input id="validateId" class="clazz">

JavaScript

jQuery.fn.numeric = function (pattern) 
{
    $(this).keypress(function(e)
    {
         var sChar = String.fromCharCode(!e.charCode ? e.which : event.charCode);
        e.preventDefault();
        var sPrev = $(this).val();
        if(!pattern.test(sChar)){
            return false;
        } else {
            sPrev = sPrev + sChar;
        }
        
        $(this).val(sPrev);
        
    });
    
};

$("#validateId").numeric(/^-?\d*\.?\d*$/);