register , login model complated. plagiraism component complated(essential part of main page is complated )
This commit is contained in:
40
src/features/auth/register/lib/validateRegister.ts
Normal file
40
src/features/auth/register/lib/validateRegister.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
export interface RegisterErrors {
|
||||
name?: string;
|
||||
surname?: string;
|
||||
phone?: string;
|
||||
oferta?: string;
|
||||
}
|
||||
|
||||
export function validateRegister(data: {
|
||||
name: string;
|
||||
surname: string;
|
||||
phone: string;
|
||||
oferta?: boolean;
|
||||
}): 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';
|
||||
}
|
||||
|
||||
const digits = data.phone.replace(/\D/g, '');
|
||||
if (!digits) {
|
||||
errors.phone = 'Phone is required';
|
||||
} else if (digits.length !== 9) {
|
||||
errors.phone = 'Enter a valid 9-digit phone number';
|
||||
}
|
||||
|
||||
if (!data.oferta) {
|
||||
errors.oferta = 'You must accept the terms to continue';
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
Reference in New Issue
Block a user