-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
45 lines (36 loc) · 1.43 KB
/
script.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
35
36
37
38
39
40
41
42
43
44
45
const form = document.getElementById('form');
const input = document.querySelectorAll('input');
const btn = document.querySelector('.btn');
const firstName = document.getElementById('first_name');
const lastName = document.getElementById('last_name');
const email = document.getElementById('email');
const password = document.getElementById('password');
const toastmsg = document.querySelector('.toast-success');
email.addEventListener('input', emailValidation)
// This function is just check for the regEx pattern for valid email, the regEx pattern is part of the form markup. It does actively as the user types so removes error as soon as it passes the regEx pattern.
function emailValidation (e) {
if (email.validity.patternMismatch) {
email.parentElement.classList.add('error');
} else {
email.parentElement.classList.remove('error');
}
}
form.addEventListener('submit', (e) => {
e.preventDefault();
input.forEach((item) => {
if(item.validity.valueMissing) {
item.parentElement.classList.add('error');
} else {
if (item.name === "email") {
if (!email.validity.patternMismatch) {
item.parentElement.classList.add('error');
}
}
item.parentElement.classList.remove('error');
toastmsg.classList.add('show');
setTimeout(function() {
toastmsg.classList.remove('show');
},3000)
}
})
});