JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="txtname" name="txtname">
JavaScript
$("#txtname").on('keypress',function(){
if($(this).val().length>20){
alert("error message");
return false;
}
});