This gives real-time visual feedback as the user types.
let input = document.querySelector('input');
input.addEventListener('input', function() {
let value = input.value;
if (value.length === 0) {
input.style.borderColor = 'gray';
} else if (value.length < 3) {
input.style.borderColor = 'red';
} else {
input.style.borderColor = 'green';
}
});