55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
// utils/registerValidation.js
|
|
|
|
const validateEmail = (email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email?.trim());
|
|
|
|
// يدعم الأرقام مع البادئات اختياريًا
|
|
const validatePhone = (phone) => /^(09|05)[0-9]{8}$/.test(phone?.trim());
|
|
|
|
export const validateStep1 = (formData, setErrors, t) => {
|
|
const newErrors = {};
|
|
|
|
if (!formData.firstName?.trim()) newErrors.firstName = t("register.firstNameRequired");
|
|
if (!formData.lastName?.trim()) newErrors.lastName = t("register.lastNameRequired");
|
|
|
|
if (!formData.email?.trim()) {
|
|
newErrors.email = t("register.emailRequired");
|
|
} else if (!validateEmail(formData.email)) {
|
|
newErrors.email = t("register.emailInvalid");
|
|
}
|
|
|
|
if (!formData.phone?.trim()) {
|
|
newErrors.phone = t("register.phoneRequired");
|
|
} else if (!validatePhone(formData.phone)) {
|
|
newErrors.phone = `${t("register.phoneInvalid")} (${t("register.phoneMustStartWith")} 09/05)`;
|
|
}
|
|
|
|
if (!formData.whatsapp?.trim()) {
|
|
newErrors.whatsapp = t("register.whatsappRequired");
|
|
} else if (!validatePhone(formData.whatsapp)) {
|
|
newErrors.whatsapp = `${t("register.phoneInvalid")} (${t("register.phoneMustStartWith")} 09/05)`;
|
|
}
|
|
|
|
if (!formData.password) {
|
|
newErrors.password = t("register.passwordRequired");
|
|
} else if (formData.password.length < 6) {
|
|
newErrors.password = t("validation.passwordMinLength");
|
|
}
|
|
|
|
if (formData.password !== formData.confirmPassword) {
|
|
newErrors.confirmPassword = t("validation.passwordsMatch");
|
|
}
|
|
|
|
setErrors(newErrors);
|
|
return Object.keys(newErrors).length === 0;
|
|
};
|
|
|
|
export const validateStep2 = (idImages, setErrors, t) => {
|
|
const newErrors = {};
|
|
|
|
if (!idImages?.front) newErrors.front = t("register.frontIdRequired");
|
|
if (!idImages?.back) newErrors.back = t("register.backIdRequired");
|
|
|
|
setErrors(newErrors);
|
|
return Object.keys(newErrors).length === 0;
|
|
};
|