I don’t really have a code snippet, I just thought about it and tried this, but it didn’t work
const checkUserEmail = function (e) {
const regex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$/;
e.preventDefault();
if (!regex.test(inputEmail.value)) {
this.classList.toggle(".error");
} else {
return (inputEmail.value = "");
}
};
form.addEventListener("submit", checkUserEmail, false);
Remove dot . in the class name:
form.classList.toggle("error")
This should work just fine.