-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (39 loc) · 1.42 KB
/
Copy pathscript.js
File metadata and controls
45 lines (39 loc) · 1.42 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
function validateForm() {
const fullName = document.getElementById("fullName").value.trim();
const email = document.getElementById("email").value.trim();
const password = document.getElementById("password").value;
const confirmPassword = document.getElementById("confirmPassword").value;
const age = document.getElementById("age").value;
// Full Name: not empty & at least 2 words
if (fullName === "" || fullName.split(" ").length < 2) {
alert("Full Name must contain at least two words.");
return false;
}
// Email format
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailPattern.test(email)) {
alert("Please enter a valid email address.");
return false;
}
// Password rules
const passwordPattern = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).{8,}$/;
if (!passwordPattern.test(password)) {
alert(
"Password must be at least 8 characters long, contain one uppercase letter, one number, and one special character."
);
return false;
}
// Confirm Password
if (password !== confirmPassword) {
alert("Passwords do not match.");
return false;
}
// Age check
if (age < 18) {
alert("You must be at least 18 years old to register.");
return false;
}
// Success
alert("Registration successful!");
return true;
}