JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" value="Enter only a number" />

JavaScript

$(function() {
    var prev="";
    $("input").click(function () {
        $(this).select();
    });
    $("input").keyup(function() {  
        if(/^[-+]?[0-9]*\.?[0-9]*$/.test(this.value))
            prev = this.value;
        else
            this.value = prev;
    });
});