-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
23 lines (19 loc) · 772 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const sendBtn = document.querySelector(".email-btn");
const errorMsg = document.querySelector(".error-msg");
const inputEl = document.querySelector(".input-field");
const emailValidation = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
const timeoutFunc = setTimeout(() => {
errorMsg.style.display = "none";
}, 3000);
sendBtn.addEventListener("click", function () {
if (inputEl.value.length === 0 || !inputEl.value.match(emailValidation)) {
errorMsg.style.display = "inline";
errorMsg.textContent = "Please enter a valid email address";
return timeoutFunc;
} else {
errorMsg.style.display = "inline";
errorMsg.style.color = "green";
errorMsg.textContent = "Thank you for subscribing to our newsletter!";
return timeoutFunc;
}
});