Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/components/SignupPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,36 @@ export default function SignUp() {
e.preventDefault();
setError("");

const { name, email, password, confirmPassword } = formData;

// Name validation: only letters and spaces
const nameRegex = /^[a-zA-Z\s]+$/;
if (!name.trim()) {
setError("Name is required");
return;
} else if (!nameRegex.test(name)) {
setError("Name can only contain letters and spaces");
return;
}

// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
setError("Please enter a valid email address");
return;
}

// Strong password validation
const strongPasswordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*(),.?":{}|<>]).{8,}$/;
if (!strongPasswordRegex.test(password)) {
setError(
"Password must be at least 8 characters and include uppercase, lowercase, number, and special character"
);
return;
}

// Password match check
if (formData.password !== formData.confirmPassword) {
if (password !== confirmPassword) {
setError("Passwords do not match");
return;
}
Expand Down