-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (32 loc) · 1.14 KB
/
Copy pathscript.js
File metadata and controls
46 lines (32 loc) · 1.14 KB
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
// 1. when someone clicks on the submit button an event will be triggered
const submitBtn = document.getElementById('submit');
const form = document.getElementById('form');
const error_name = document.getElementById('error_name');
const error_email = document.getElementById('error_email');
const success = document.querySelector("#successMessage");
form.addEventListener('submit', check);
function check(event) {
event.preventDefault();
const name = document.getElementById('name');
const nameValue = name.value.trim();
if(nameValue ==""){
error_name.classList.remove("d-none");
}
else{
error_name.classList.add('d-none');
}
const email = document.getElementById('email');
const emailValue = email.value.trim();
if(emailValue == ""){
error_email.classList.remove("d-none");
}else{
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emailRegex.test(emailValue)){
error_email.classList.add('d-none');
success.classList.remove('d-none');
}else{
error_email.classList.remove('d-none');
}
}
form.reset();
}