JSFiddle - React, Tailwind, and code Playground

HTML

<input type='text' id='range' data-min=1, data-max=20 value=1>

JavaScript

$(document).on('keypress', "#range", function (e) {
    curValue = this.value + String.fromCharCode(e.which || e.keyCode);
    if (/^\d+$/.test(curValue)) {
        if ($(this).data('min') > curValue || $(this).data('max') < curValue) {
            return false
        }
        return true
    } else {
        return false;
    }
})