JSFiddle - React, Tailwind, and code Playground

by Gereltod Gotsbayar

HTML

<input type="text" class="number" />

CSS

.number {
    padding: 5px 10px;
    font-size: 16px;
}

JavaScript

$('.number').keypress(function(event) {
    if (event.which != 46 && (event.which < 47 || event.which > 59))
    {
        event.preventDefault();
        if ((event.which == 46) && ($(this).indexOf('.') != -1)) {
            event.preventDefault();
        }
    }
});