-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidation.js
More file actions
109 lines (93 loc) · 2.89 KB
/
Copy pathvalidation.js
File metadata and controls
109 lines (93 loc) · 2.89 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Updated validation.js
function validateContactForm() {
const form = document.contactForm;
// Validate First Name
if (form.fname.value.trim() === "") {
alert("Please provide your first name!");
form.fname.focus();
return false;
}
// Validate Last Name
if (form.lname.value.trim() === "") {
alert("Please provide your last name!");
form.lname.focus();
return false;
}
// Validate Email
const email = form.emailAddress.value.trim();
if (email === "") {
alert("Please provide your email address!");
form.emailAddress.focus();
return false;
}
const atpos = email.indexOf("@");
const dotpos = email.lastIndexOf(".");
if (atpos < 1 || (dotpos - atpos < 2)) {
alert("Please provide a correct email address!");
form.emailAddress.focus();
return false;
}
// Validate Subject
if (form.subject.value.trim() === "") {
alert("Please provide a subject!");
form.subject.focus();
return false;
}
// Validate Message
if (form.message.value.trim() === "") {
alert("Please provide your message!");
form.message.focus();
return false;
}
return true;
}
function validateVolunteerForm() {
const form = document.volunteerForm;
// Validate Full Name
if (form.name.value.trim() === "") {
alert("Please provide your full name!");
form.name.focus();
return false;
}
// Validate Phone Number
const phone = form.phone.value.trim();
if (phone === "") {
alert("Please provide your phone number!");
form.phone.focus();
return false;
}
// Basic phone number validation (Malaysian format)
const phoneRegex = /^0\d{1,2}-\d{7,8}$/;
if (!phoneRegex.test(phone)) {
alert("Please provide a valid phone number (e.g., 012-3456789)!");
form.phone.focus();
return false;
}
// Validate Email
const email = form.email.value.trim();
if (email === "") {
alert("Please provide your email address!");
form.email.focus();
return false;
}
const atpos = email.indexOf("@");
const dotpos = email.lastIndexOf(".");
if (atpos < 1 || (dotpos - atpos < 2)) {
alert("Please provide a correct email address!");
form.email.focus();
return false;
}
// Validate Volunteer Area
if (form.area.value.trim() === "") {
alert("Please provide the area you can volunteer in!");
form.area.focus();
return false;
}
// Validate Availability
if (form.availability.value.trim() === "") {
alert("Please provide your availability!");
form.availability.focus();
return false;
}
return true;
}