Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion app/contact/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface FormFields {
interface FormErrors {
fullName?: string;
email?: string;
phone?: string;
subject?: string;
message?: string;
}
Expand Down Expand Up @@ -97,6 +98,8 @@ function validate(fields: FormFields): FormErrors {
errors.fullName = 'Full name is required.';
} else if (fields.fullName.trim().length < 2) {
errors.fullName = 'Name must be at least 2 characters.';
} else if (!/^[A-Za-z]+(?:[ '-][A-Za-z]+)*$/.test(fields.fullName.trim())) {
errors.fullName = 'Please enter a valid name.';
}

if (!fields.email.trim()) {
Expand All @@ -105,6 +108,10 @@ function validate(fields: FormFields): FormErrors {
errors.email = 'Please enter a valid email address.';
}

if (fields.phone.trim() && !/^\+?[0-9\s()-]{7,15}$/.test(fields.phone.trim())) {
errors.phone = 'Please enter a valid phone number.';
}

if (!fields.subject.trim()) {
errors.subject = 'Subject is required.';
}
Expand Down Expand Up @@ -497,7 +504,7 @@ export default function ContactPage() {
</Field>

{/* Phone — optional */}
<Field id="contact-phone" label="Phone Number">
<Field id="contact-phone" label="Phone Number" error={errors.phone}>
<div className="relative">
<Phone
size={16}
Expand Down
2 changes: 2 additions & 0 deletions app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export default function SignUpPage() {

if (!fields.fullName.trim()) {
newErrors.fullName = 'Full Name is required';
} else if (!/^[A-Za-z]+(?:[ '-][A-Za-z]+)*$/.test(fields.fullName.trim())) {
newErrors.fullName = 'Please enter a valid name';
}

if (!fields.email.trim()) {
Expand Down
Loading