JSFiddle - React, Tailwind, and code Playground
HTML
<input id="foo">
JavaScript
var MIN = 0;
var MAX = 500;
$('#foo').on('keyup', function(e) {
var v = parseInt($(this).val());
if (isNaN(v)) {
return $(this).val(MIN);
}
if ($(this).val() < MIN) {
$(this).val(MIN);
} else if ($(this).val() > MAX) {
$(this).val(MAX);
} else {
$(this).val(v);
}
});