diff --git a/app/contact/page.tsx b/app/contact/page.tsx index eee6fa336..a0d94b946 100644 --- a/app/contact/page.tsx +++ b/app/contact/page.tsx @@ -33,6 +33,7 @@ interface FormFields { interface FormErrors { fullName?: string; email?: string; + phone?: string; subject?: string; message?: string; } @@ -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()) { @@ -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.'; } @@ -497,7 +504,7 @@ export default function ContactPage() { {/* Phone — optional */} - +