-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.js
34 lines (32 loc) · 1.01 KB
/
validation.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
33
34
const form = document.getElementById('form-contact');
const inputName = document.getElementById('name');
const email = document.getElementById('email');
const message = document.getElementById('message');
const msg = document.querySelector('.show-msg');
function validationEmail(e) {
if (email.value !== email.value.toLowerCase()) {
e.preventDefault();
msg.style.display = 'block';
msg.innerHTML = 'The email must be in lowercase';
} else {
const data = {
name: inputName.value,
email: email.value,
message: message.value,
};
localStorage.setItem('contactData', JSON.stringify(data));
}
}
form.addEventListener('submit', validationEmail);
const getData = JSON.parse(localStorage.getItem('contactData')) || {};
window.addEventListener('load', () => {
if (Object.keys(getData).length) {
inputName.value = getData.name;
email.value = getData.email;
message.value = getData.message;
} else {
inputName.value = '';
email.value = '';
message.value = '';
}
});