diff --git a/src/components/RegisterPage.tsx b/src/components/RegisterPage.tsx index f6ea833..32f9e07 100644 --- a/src/components/RegisterPage.tsx +++ b/src/components/RegisterPage.tsx @@ -37,19 +37,56 @@ export default function RegisterPage() { setFormData(prev => ({ ...prev, [field]: value })); }; - const validateForm = () => { - if (!formData.firstName.trim()) return toast.error('First name is required'), false; - if (!formData.lastName.trim()) return toast.error('Last name is required'), false; - if (!formData.emailAddress.includes('@')) return toast.error('Invalid email address'), false; - if (!formData.isdCode.startsWith("+")) toast.error("ISD code must start with '+'"), false; - if (!/^\+\d+$/.test(formData.isdCode)) toast.error("ISD code must contain only numbers after '+'"), false; - if (!/^\d+$/.test(formData.mobileNumber)) return toast.error('Invalid mobile number'), false; - if (!formData.address1.trim()) return toast.error('Address required'), false; - if (!formData.city.trim()) return toast.error('City required'), false; - if (!formData.state.trim()) return toast.error('State required'), false; - if (!/^\d+$/.test(formData.postalCode)) return toast.error('Postal code should only contain numbers'), false; - return true; - }; + const validateForm = () => { + // First Name + if (!formData.firstName.trim()) return toast.error('First name is required'), false; + if (!/^[A-Za-z]+$/.test(formData.firstName)) return toast.error('First name must contain only alphabets'), false; + if (formData.firstName.length < 2 || formData.firstName.length > 50) return toast.error('First name must be between 2 and 50 characters'), false; + + // Last Name + if (!formData.lastName.trim()) return toast.error('Last name is required'), false; + if (!/^[A-Za-z]+$/.test(formData.lastName)) return toast.error('Last name must contain only alphabets'), false; + if (formData.lastName.length < 2 || formData.lastName.length > 50) return toast.error('Last name must be between 2 and 50 characters'), false; + + // Email + if (!formData.emailAddress.includes('@')) return toast.error('Invalid email address'), false; + + // ISD Code + if (!formData.isdCode.startsWith("+")) return toast.error("ISD code must start with '+'"), false; + if (!/^\+\d+$/.test(formData.isdCode)) return toast.error("ISD code must contain only numbers after '+'"), false; + + // Mobile Number + if (!/^\d+$/.test(formData.mobileNumber)) return toast.error('Invalid mobile number'), false; + if (formData.mobileNumber.length < 7 || formData.mobileNumber.length > 15) return toast.error('Mobile number must be between 7 and 15 digits'), false; + + // Address Line 1 + if (!formData.address1.trim()) return toast.error('Address required'), false; + if (!/^[A-Za-z0-9\s]+$/.test(formData.address1)) return toast.error('Address must be alphanumeric'), false; + if (formData.address1.length < 5 || formData.address1.length > 100) return toast.error('Address must be between 5 and 100 characters'), false; + + // City + if (!formData.city.trim()) return toast.error('City required'), false; + if (!/^[A-Za-z\s]+$/.test(formData.city)) return toast.error('City must contain only alphabets'), false; + if (formData.city.length < 2 || formData.city.length > 50) return toast.error('City must be between 2 and 50 characters'), false; + + // State + if (!formData.state.trim()) return toast.error('State required'), false; + if (!/^[A-Za-z\s]+$/.test(formData.state)) return toast.error('State must contain only alphabets'), false; + if (formData.state.length < 2 || formData.state.length > 50) return toast.error('State must be between 2 and 50 characters'), false; + + // Country + if (!formData.country.trim()) return toast.error('Country required'), false; + if (!/^[A-Za-z\s]+$/.test(formData.country)) return toast.error('Country must contain only alphabets'), false; + if (formData.country.length < 2 || formData.country.length > 50) return toast.error('Country must be between 2 and 50 characters'), false; + + // Postal Code + if (!/^\d+$/.test(formData.postalCode)) return toast.error('Postal code should only contain numbers'), false; + if (formData.postalCode.length < 4 || formData.postalCode.length > 10) return toast.error('Postal code must be between 4 and 10 digits'), false; + + return true; +}; + + const handleRegister = async () => { if (!validateForm()) return; @@ -79,182 +116,182 @@ export default function RegisterPage() { }; return ( -
- {/* Navbar */} - +
+ {/* Navbar */} + - {/* Main Content */} -
-
+ {/* Main Content */} +
+
- {/* Header */} -
-

- Create Account -

-

- Register to get started with City Cards -

+ {/* Header */} +
+

+ Create Account +

+

+ Register to get started with City Cards +

+
+ + {/* Form Container */} +
+ + {/* Personal Info */} +
+

+ Personal Information +

+ +
+
+ + handleInputChange('firstName', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('lastName', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+ +
+ + handleInputChange('emailAddress', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+
+ + handleInputChange('isdCode', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('mobileNumber', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+
+ + {/* Address */} +
+

+ Address Information +

+ +
+ + handleInputChange('address1', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('address2', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+
+ + handleInputChange('city', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('state', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+ +
+
+ + handleInputChange('country', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('postalCode', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+
+ + {helperText && ( +

{helperText}

+ )} + + + +
+
- {/* Form Container */} -
- - {/* Personal Info */} -
-

- Personal Information -

- -
-
- - handleInputChange('firstName', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
- - handleInputChange('lastName', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
-
- -
- - handleInputChange('emailAddress', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
-
- - handleInputChange('isdCode', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
- - handleInputChange('mobileNumber', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
-
-
- - {/* Address */} -
-

- Address Information -

- -
- - handleInputChange('address1', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
- - handleInputChange('address2', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
-
- - handleInputChange('city', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
- - handleInputChange('state', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
-
- -
-
- - handleInputChange('country', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
- -
- - handleInputChange('postalCode', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl mt-1" - /> -
-
-
- - {helperText && ( -

{helperText}

- )} - - - + {/* Footer */} +
+
-
- - {/* Footer */} -
-
-
); } \ No newline at end of file