JSFiddle - React, Tailwind, and code Playground

HTML

<form>
    <input type="text" />

    <input type="submit" />
</form>

CSS

.err_uname {
    
   color: red;enter the username
}

JavaScript

var error = false;
$('input[type="text"]').on('keyup', function () {
    if (this.value === '') {
        error = true;
        $(this).addClass('err_uname');
    } else {
        error = false;
        $(this).removeClass('err_uname');
    }
});
$('form').on('submit', function () {
    $(this).find('input').trigger('keyup');
    console.log(!error);
    return !error;//will return true if there is not error, and false if there is an error
});