-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
32 lines (27 loc) · 911 Bytes
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const form = document.getElementById("form");
const emailInput = document.getElementById("email");
const emailLabel = document.getElementById("email-label");
const emailRegex = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
form.addEventListener("submit", validateEmail);
emailInput.addEventListener("input", validateEmail);
function validateEmail() {
if (emailInput.value.length > 5) {
if (emailRegex.test(emailInput.value)) {
removeEmailError();
} else {
setEmailError();
}
}
}
function setEmailError() {
if (!emailInput.classList.contains("input-email-error")) {
emailInput.classList.add("input-email-error");
emailLabel.style.visibility = "visible";
}
}
function removeEmailError() {
if (emailInput.classList.contains("input-email-error")) {
emailInput.classList.remove("input-email-error");
emailLabel.style.visibility = "hidden";
}
}