JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="txtChar" name="txtChar" class="CsstxtChar" maxlength="4"/>
JavaScript
const pattern = new RegExp('[0-9.]');
$('#txtChar').on('keypress', function(e){
debugger;
const res = pattern.test(e.key);
if(!res) {
e.preventDefault();
}
});