-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
20 lines (18 loc) · 768 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const form = document.querySelector('form')
const errrorMessage = document.getElementById('error-message')
const emailBackground = document.getElementById('email')
form.addEventListener('submit', (e) => {
e.preventDefault()
const email = document.getElementById('email').value
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (emailRegex.test(email)) {
errrorMessage.classList.remove('error-message')
emailBackground.classList.remove('error-background')
localStorage.setItem('email', email)
window.location.href = `./page2.html?email=${encodeURIComponent(email)}`
} else {
errrorMessage.textContent = 'Valid email required'
errrorMessage.classList.add('error-message')
emailBackground.classList.add('error-background')
}
})