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