JSFiddle - React, Tailwind, and code Playground

by CME64

HTML

<input type="text" id="txt"/>

JavaScript

$('#txt').on('keydown keyup change', function(){
    var txt = $(this).val();
    if(!(/^[1-9]/.test(txt)&/\d$/.test(txt))) $(this).val(txt.substring(0,txt.length-1));
});