JSFiddle - React, Tailwind, and code Playground
HTML
<input type='tel' class='number' maxlength="4">
JavaScript
$(".number").on('input', function() {
this.value = this.value.replace(/[^0-9]/g, '');
});
<input type='tel' class='number' maxlength="4">
$(".number").on('input', function() {
this.value = this.value.replace(/[^0-9]/g, '');
});