JSFiddle - React, Tailwind, and code Playground
HTML
<input id="validateId" class="clazz">
JavaScript
jQuery.fn.numeric = function (pattern)
{
var jqElement = $(this), prevValue;
jqElement.keydown(function()
{
prevValue = jqElement.val();
})
jqElement.keyup(function(e)
{
if (!pattern.test(jqElement.val()))
{
jqElement.val(prevValue);
e.preventDefault();
}
prevValue = ""
})
};
$("#validateId").numeric(/^-?\d*\.?\d*$/);