@kimodev1990
Posted
Really great work, Just a few feedbacks :
- If I don't enter an email or entered a wrong form of email in the input , Then you entered the right email , the label error doesn't disappears .
- If you add space at the beginning or end of email ( not between email ), It gives an error.
You could use in javascript:
const form = document.querySelector(".class name you provide in form tag");
const inputEmail = document.querySelector(".class name you provide in input tag");
const errorLabel = document.querySelector(".class name you provide for error");
form.addEventListener("submit", (event) => {
event.preventDefault();
if (validateEmail(inputEmail.value.trim()) === true) {
showError();
} else {
hideError();
}
});
function validateEmail(inputText) {
const mailFormat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if (inputText.match(mailFormat)) {
return false;
}
return true;
}
function showError() {
errorLabel.classList.remove("hidden");
}
function hideError() {
errorLabel.classList.add("hidden");
}
Hope you find this Helpful.
Marked as helpful
@jilenski
Posted
@kimodev1990 Thank you so much for checking! š I wasn't able to notice that. Your feedback was really helpful. I have already made a revision to my code. š
@kimodev1990
Posted
@jilenski You're always welcome, Anytime....