<input class="class1" type="text" name="test" value="">
.class1 {
background: white;
}
.class2 {
background: red;
}
document.querySelector('input').addEventListener('input', function() {
this.value = this.value.replace(/[!@#№$;%:^&?*()]/, '');
if (this.value.length >= 8) {
this.classList.add('class2');
} else {
this.classList.remove('class2');
}
});