main #34

Merged
Hemant.Vishwakarma merged 6 commits from main into testing 2026-04-24 16:42:03 +00:00
3 changed files with 69 additions and 73 deletions
Showing only changes of commit e3fde4bb17 - Show all commits

View File

@@ -46,56 +46,58 @@ export default function RegisterPage() {
setFormData(prev => ({ ...prev, [field]: value }));
};
const validateForm = () => {
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 (/\s/.test(formData.firstName)) return toast.error('First name must not contain spaces'), false;
if (!/^[A-Za-z]+$/.test(formData.firstName)) return toast.error('First name must contain only letters (AZ)'), 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 (/\s/.test(formData.lastName)) return toast.error('Last name must not contain spaces'), false;
if (!/^[A-Za-z]+$/.test(formData.lastName)) return toast.error('Last name must contain only letters (AZ)'), false;
if (formData.lastName.length < 2 || formData.lastName.length > 50) return toast.error('Last name must be between 2 and 50 characters'), false;
// Email (IMPROVED from 1st function)
if (!formData.emailAddress.trim()) return toast.error('Email is required'), false;
if (!/\S+@\S+\.\S+/.test(formData.emailAddress)) return toast.error('Valid email address required'), false;
// Email
if (!formData.emailAddress.trim()) return toast.error('Email address is required'), false;
if (!/\S+@\S+\.\S+/.test(formData.emailAddress)) return toast.error('Enter a valid email (e.g. name@example.com)'), false;
// ISD Code
// ISD
if (!formData.isdCode.trim()) return toast.error('ISD code is required'), false;
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;
if (/\s/.test(formData.isdCode)) return toast.error('ISD code must not contain spaces'), false;
if (!formData.isdCode.startsWith('+')) return toast.error("ISD code must start with '+' (e.g. +91)"), false;
if (!/^\+\d+$/.test(formData.isdCode)) return toast.error("ISD code must contain only digits after '+'"), false;
// Mobile Number (IMPROVED with required check)
// Phone
if (!formData.mobileNumber.trim()) return toast.error('Mobile number is required'), false;
if (!/^\d+$/.test(formData.mobileNumber)) return toast.error('Invalid mobile number'), false;
if (/\s/.test(formData.mobileNumber)) return toast.error('Mobile number must not contain spaces'), false;
if (!/^\d+$/.test(formData.mobileNumber)) return toast.error('Mobile number must contain only digits (09)'), 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 (UPDATED regex from 3rd function)
if (!formData.address1.trim()) return toast.error('Address required'), false;
if (!/^[A-Za-z0-9\s,\-.]+$/.test(formData.address1)) return toast.error('Address contains invalid characters'), false;
// Address
if (!formData.address1.trim()) return toast.error('Address is required'), false;
if (!/^[A-Za-z0-9\s,\-.]+$/.test(formData.address1)) return toast.error('Address can only contain letters, numbers, spaces, commas, dots, and hyphens'), false;
if (formData.address1.length < 5 || formData.address1.length > 100) return toast.error('Address must be between 5 and 100 characters'), false;
// City (IMPROVED with no multiple spaces)
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;
// City
if (!formData.city.trim()) return toast.error('City is required'), false;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.city)) return toast.error('City can only contain letters and spaces'), false;
if (/\s{2,}/.test(formData.city)) return toast.error('City must not contain multiple consecutive spaces'), false;
if (formData.city.length < 2 || formData.city.length > 50) return toast.error('City must be between 2 and 50 characters'), false;
// State (IMPROVED similar to city)
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;
// State
if (!formData.state.trim()) return toast.error('State is required'), false;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.state)) return toast.error('State can only contain letters and spaces'), false;
if (/\s{2,}/.test(formData.state)) return toast.error('State must not contain multiple consecutive spaces'), false;
if (formData.state.length < 2 || formData.state.length > 50) return toast.error('State must be between 2 and 50 characters'), false;
// Country (IMPROVED regex from 3rd)
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;
// Country
if (!formData.country.trim()) return toast.error('Country is required'), false;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.country)) return toast.error('Country can only contain letters and spaces'), false;
// Postal Code (IMPROVED from 3rd: alphanumeric allowed)
// Postal Code
if (!formData.postalCode.trim()) return toast.error('Postal code is required'), false;
if (!/^[A-Za-z0-9\s\-]+$/.test(formData.postalCode)) return toast.error('Postal code contains invalid characters'), false;
if (/\s/.test(formData.postalCode)) return toast.error('Postal code must not contain spaces'), false;
if (!/^[A-Za-z0-9]+$/.test(formData.postalCode)) return toast.error('Postal code must contain only letters and numbers'), false;
if (formData.postalCode.length < 4 || formData.postalCode.length > 10) return toast.error('Postal code must be between 4 and 10 characters'), false;
return true;

View File

@@ -230,53 +230,57 @@ export function PaymentDetailsPage({
const [errors, setErrors] = useState<Record<string, string>>({});
const validate = () => {
const validate = () => {
const e: Record<string, string> = {};
if (selectedTab === 'gift') {
// First Name
if (!giftFirstName.trim()) e.giftFirstName = 'Required';
else if (!/^[A-Za-z]+$/.test(giftFirstName)) e.giftFirstName = 'Only alphabets allowed';
else if (giftFirstName.length < 2 || giftFirstName.length > 50) e.giftFirstName = 'Must be 250 characters';
if (!giftFirstName.trim()) e.giftFirstName = 'First name is required';
else if (/\s/.test(giftFirstName)) e.giftFirstName = 'First name must not contain spaces';
else if (!/^[A-Za-z]+$/.test(giftFirstName)) e.giftFirstName = 'First name must contain only letters (AZ)';
else if (giftFirstName.length < 2 || giftFirstName.length > 50) e.giftFirstName = 'First name must be between 2 and 50 characters';
// Last Name
if (!giftLastName.trim()) e.giftLastName = 'Required';
else if (!/^[A-Za-z]+$/.test(giftLastName)) e.giftLastName = 'Only alphabets allowed';
else if (giftLastName.length < 2 || giftLastName.length > 50) e.giftLastName = 'Must be 250 characters';
if (!giftLastName.trim()) e.giftLastName = 'Last name is required';
else if (/\s/.test(giftLastName)) e.giftLastName = 'Last name must not contain spaces';
else if (!/^[A-Za-z]+$/.test(giftLastName)) e.giftLastName = 'Last name must contain only letters (AZ)';
else if (giftLastName.length < 2 || giftLastName.length > 50) e.giftLastName = 'Last name must be between 2 and 50 characters';
// ISD Code
if (!giftIsd.trim()) e.giftIsd = 'Required';
else if (!giftIsd.startsWith('+')) e.giftIsd = "Must start with '+'";
else if (!/^\+\d+$/.test(giftIsd)) e.giftIsd = "Only numbers allowed after '+'";
if (!giftIsd.trim()) e.giftIsd = 'ISD code is required';
else if (/\s/.test(giftIsd)) e.giftIsd = 'ISD code must not contain spaces';
else if (!giftIsd.startsWith('+')) e.giftIsd = "ISD code must start with '+' (e.g. +91)";
else if (!/^\+\d+$/.test(giftIsd)) e.giftIsd = "ISD code must contain only digits after '+'";
// Email
if (!giftEmail.trim()) e.giftEmail = 'Required';
else if (!/\S+@\S+\.\S+/.test(giftEmail)) e.giftEmail = 'Valid email required';
if (!giftEmail.trim()) e.giftEmail = 'Email address is required';
else if (!/\S+@\S+\.\S+/.test(giftEmail)) e.giftEmail = 'Enter a valid email (e.g. name@example.com)';
// Phone
if (!giftPhone.trim()) e.giftPhone = 'Required';
else if (!/^\d+$/.test(giftPhone)) e.giftPhone = 'Only numbers allowed';
else if (giftPhone.length < 7 || giftPhone.length > 15) e.giftPhone = 'Must be 715 digits';
if (!giftPhone.trim()) e.giftPhone = 'Phone number is required';
else if (/\s/.test(giftPhone)) e.giftPhone = 'Phone number must not contain spaces';
else if (!/^\d+$/.test(giftPhone)) e.giftPhone = 'Phone number must contain only digits (09)';
else if (giftPhone.length < 7 || giftPhone.length > 15) e.giftPhone = 'Phone number must be between 7 and 15 digits';
// Message
if (!giftMessage.trim()) e.giftMessage = 'Required';
else if (giftMessage.length < 5 || giftMessage.length > 500) e.giftMessage = 'Must be 5500 characters';
if (!giftMessage.trim()) e.giftMessage = 'Message is required';
else if (giftMessage.length < 5) e.giftMessage = 'Message must be at least 5 characters long';
else if (giftMessage.length > 500) e.giftMessage = 'Message must not exceed 500 characters';
// City
if (!giftCity.trim()) e.giftCity = 'Required';
else if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(giftCity)) e.giftCity = 'Only alphabets allowed';
else if (/\s{2,}/.test(giftCity)) e.giftCity = 'No multiple spaces';
else if (giftCity.length < 2 || giftCity.length > 50) e.giftCity = 'Must be 250 characters';
if (!giftCity.trim()) e.giftCity = 'City is required';
else if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(giftCity)) e.giftCity = 'City can only contain letters and spaces';
else if (/\s{2,}/.test(giftCity)) e.giftCity = 'City must not contain multiple consecutive spaces';
else if (giftCity.length < 2 || giftCity.length > 50) e.giftCity = 'City must be between 2 and 50 characters';
// Country
if (!giftCountry.trim()) e.giftCountry = 'Required';
else if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(giftCountry)) e.giftCountry = 'Only alphabets allowed';
else if (giftCountry.length < 2 || giftCountry.length > 50) e.giftCountry = 'Must be 250 characters';
if (!giftCountry.trim()) e.giftCountry = 'Country is required';
else if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(giftCountry)) e.giftCountry = 'Country can only contain letters and spaces';
else if (giftCountry.length < 2 || giftCountry.length > 50) e.giftCountry = 'Country must be between 2 and 50 characters';
}
return e;
};
const [isRedirecting, setIsRedirecting] = useState(false);
const handlePayment = async () => {

View File

@@ -130,41 +130,31 @@ export function ProfilePage({
}, [userDetails])
const validateForm = () => {
// First Name (TC-013)
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;
if (/\s/.test(formData.firstName)) return toast.error('First name must not contain spaces'), false;
if (!/^[A-Za-z]+$/.test(formData.firstName)) return toast.error('First name must contain only letters'), false;
// Last Name (TC-014)
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;
if (/\s/.test(formData.lastName)) return toast.error('Last name must not contain spaces'), false;
if (!/^[A-Za-z]+$/.test(formData.lastName)) return toast.error('Last name must contain only letters'), false;
// Mobile Number (TC-016)
if (!formData.phone.trim()) return toast.error('Mobile number is required'), false;
if (!/^\d+$/.test(formData.phone)) return toast.error('Mobile number must contain only numbers'), false;
if (formData.phone.length < 7 || formData.phone.length > 15) return toast.error('Mobile number must be between 7 and 15 digits'), false;
if (/\s/.test(formData.phone)) return toast.error('Mobile number must not contain spaces'), false;
if (!/^\d+$/.test(formData.phone)) return toast.error('Mobile number must contain only digits'), false;
// Address Line 1 (TC-019)
if (!formData.address1.trim()) return toast.error('Address is required'), false;
if (!/^[A-Za-z0-9\s,\-.]+$/.test(formData.address1)) return toast.error('Address contains invalid characters'), false;
if (formData.address1.length < 5 || formData.address1.length > 100) return toast.error('Address must be between 5 and 100 characters'), false;
// City (TC-018)
if (!formData.city.trim()) return toast.error('City is required'), false;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.city)) return toast.error('City must contain only alphabets'), false;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.city)) return toast.error('City can only contain letters and spaces'), false;
if (/\s{2,}/.test(formData.city)) return toast.error('City must not contain multiple consecutive spaces'), false;
if (formData.city.length < 2 || formData.city.length > 50) return toast.error('City must be between 2 and 50 characters'), false;
// Country (TC-017) — free text validation since no dropdown yet
if (!formData.country.trim()) return toast.error('Country is 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;
if (!/^[A-Za-z\s\-'À-ÿ]+$/.test(formData.country)) return toast.error('Country can only contain letters and spaces'), false;
// Postal Code (TC-020)
if (!formData.postalCode.trim()) return toast.error('Postal code is required'), false;
if (!/^[A-Za-z0-9\s\-]+$/.test(formData.postalCode)) return toast.error('Postal code contains invalid characters'), false;
if (formData.postalCode.length < 4 || formData.postalCode.length > 10) return toast.error('Postal code must be between 4 and 10 characters'), false;
if (/\s/.test(formData.postalCode)) return toast.error('Postal code must not contain spaces'), false;
if (!/^[A-Za-z0-9]+$/.test(formData.postalCode)) return toast.error('Postal code must contain only letters and numbers'), false;
return true;
};