JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text">

CSS

input {
    border: 1px solid #000;
}

.invalid {
    color: #f00;
    border-color: #f00;
}

JavaScript

$('input').on('input', function(){
    if ($(this).val() === '2') {
        $(this).addClass('invalid');
    } else {
        $(this).removeClass('invalid');
    }
});