-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
32 lines (25 loc) · 823 Bytes
/
form.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 savedEmail = sessionStorage.getItem('email');
if (savedEmail) {
const savedEmailDisplay = document.getElementById('savedEmail');
console.log(savedEmailDisplay);
savedEmailDisplay.textContent = savedEmail;
sessionStorage.clear();
}
const form = document.getElementById('subscribe');
const emailAddress = document.getElementById('emailAddress');
if (form) {
form.addEventListener('submit', (e) => {
let isValid = true;
if (!emailAddress.value) {
isValid = false;
}
if (null === emailAddress.value.match(/.+@.+\..+/g)) {
isValid = false;
}
if (false === isValid) {
form.classList.add('invalid');
e.preventDefault();
}
sessionStorage.setItem("email", emailAddress.value);
});
}