starkon
Version:
Complete Next.js boilerplate with authentication, i18n & CLI - Create production-ready apps instantly
34 lines (31 loc) • 1.19 kB
text/typescript
import { z } from 'zod'
/**
* Register form validation schema
*/
export const registerSchema = z
.object({
fullName: z
.string()
.min(2, 'Full name must be at least 2 characters')
.max(100, 'Full name must be less than 100 characters')
.trim(),
email: z.string().email('Please enter a valid email address').toLowerCase().trim(),
password: z
.string()
.min(8, 'Password must be at least 8 characters')
.regex(/(?=.*[a-z])/, 'Password must contain at least one lowercase letter')
.regex(/(?=.*[A-Z])/, 'Password must contain at least one uppercase letter')
.regex(/(?=.*\d)/, 'Password must contain at least one number'),
confirmPassword: z.string(),
agreedToTerms: z.boolean().refine((val) => val === true, {
message: 'You must agree to the terms and conditions',
}),
agreedToPrivacy: z.boolean().refine((val) => val === true, {
message: 'You must agree to the privacy policy',
}),
})
.refine((data) => data.password === data.confirmPassword, {
message: 'Passwords do not match',
path: ['confirmPassword'],
})
export type RegisterFormData = z.infer<typeof registerSchema>