47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
export interface RegisterErrors {
|
|
name?: string;
|
|
surname?: string;
|
|
phone?: string;
|
|
oferta?: string;
|
|
password?: string;
|
|
}
|
|
|
|
export function validateRegister(data: {
|
|
name: string;
|
|
surname: string;
|
|
phone: string;
|
|
oferta?: boolean;
|
|
password: string;
|
|
}): RegisterErrors {
|
|
const errors: RegisterErrors = {};
|
|
|
|
if (!data.name.trim()) {
|
|
errors.name = 'Name is required';
|
|
} else if (data.name.trim().length < 2) {
|
|
errors.name = 'Name must be at least 2 characters';
|
|
}
|
|
|
|
if (!data.surname.trim()) {
|
|
errors.surname = 'Surname is required';
|
|
} else if (data.surname.trim().length < 2) {
|
|
errors.surname = 'Surname must be at least 2 characters';
|
|
}
|
|
|
|
if (!data.phone || data.phone.length < 12) {
|
|
// "998" prefix (3) + 9 digits = 12
|
|
errors.phone = 'Enter a valid 9-digit phone number';
|
|
}
|
|
|
|
if (!data.password) {
|
|
errors.password = 'Password is required';
|
|
} else if (data.password.length < 6) {
|
|
errors.password = 'Password must be at least 6 characters';
|
|
}
|
|
|
|
if (!data.oferta) {
|
|
errors.oferta = 'You must accept the terms to continue';
|
|
}
|
|
|
|
return errors;
|
|
}
|