JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="TextBox1" name="TexBox1" value="" />
<span id='error' name='error'></span>
JavaScript
function monitor() {
if ($('#TextBox1').val().length > 0) {
var reg = /^([a-zA-Z]+)$/;
if (!reg.test($('#TextBox1').val())) {
$('#error').html("Only letters are allowed!");
} else {
$('#error').html("");
}
} else {
$('#error').html("");
}
}
var timer = '';
$('#TextBox1').on('focus', function () {
timer = setInterval(monitor, 100);
}).on('blur', function () {
clearInterval(timer);
});