-
Notifications
You must be signed in to change notification settings - Fork 0
/
forms2.js
42 lines (32 loc) · 1.26 KB
/
forms2.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
// now this part is for the putting for adoption form
const adoptionForm = document.getElementById("adoption-form");
adoptionForm.addEventListener('submit', (event) =>{
// since i put everything with required, there is no need to check if they have a value
// we just need to check if name and email is the right pattern
// validate name
const namePattern = /^[a-zA-Z]+(?:[' -][a-zA-Z]+)*$/;
const name = document.getElementById("name-in-adopt").value;
if (!name.trim()){
alert("Please enter a name");
event.preventDefault();
return false; // stop further processing
}
if (!namePattern.test(name)){
alert("Please enter a valid name");
event.preventDefault();
return false; // stop further processing
};
// validate email
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const email = document.getElementById("email-in-adopt").value;
if (!email.trim()){
alert("Please enter a email");
event.preventDefault();
return false; // stop further processing
}
if (!emailPattern.test(email)){
alert("Please enter a valid email (has to have @___.___)");
event.preventDefault();
return false; // stop further processing
};
});