diff --git a/src/schemas.ts b/src/schemas.ts index b72bec90..80ea73c5 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -4,7 +4,10 @@ export const MenteeApplicationSchema = z.object({ firstName: z.string().min(1, { message: 'First name cannot be empty' }), lastName: z.string().min(1, { message: 'Last name cannot be empty' }), email: z.string().email({ message: 'Invalid email address' }), - contactNo: z.string().min(1, { message: 'Contact number cannot be empty' }), + contactNo: z + .string() + .min(1, { message: 'Contact number cannot be empty' }) + .regex(/^\+[1-9]\d{1,14}$/, 'Invalid contact number'), company: z.string().min(1, { message: 'Company cannot be empty' }).optional(), profilePic: z .string() @@ -13,19 +16,26 @@ export const MenteeApplicationSchema = z.object({ .string() .min(1, { message: 'Position cannot be empty' }) .optional(), - cv: z.string().min(1, { message: 'CV cannot be empty' }), + cv: z + .string() + .min(1, { message: 'CV cannot be empty' }) + .url({ message: 'Please enter a valid link' }), isUndergrad: z.boolean(), consentGiven: z.boolean().refine((val) => val, { message: 'You must give your consent to proceed.', }), graduatedYear: z .number({ invalid_type_error: 'Graduated year is required' }) + .int({ message: 'Graduated year must be an integer' }) .refine( (data) => { - return data === undefined || (!isNaN(data) && data >= 1980); + return ( + data === undefined || + (!isNaN(data) && data >= 1980 && data <= new Date().getFullYear()) + ); }, { - message: 'Graduated year must be a year', + message: 'Graduated year must be a valid year', } ) .optional(), @@ -35,6 +45,7 @@ export const MenteeApplicationSchema = z.object({ .optional(), yearOfStudy: z .number({ invalid_type_error: 'Year of study is required' }) + .int({ message: 'Year of study must be an integer' }) .gte(1, { message: 'Year must be greater than 0' }) .lte(4, { message: 'Year must be less than or equal 4' }) .optional(),