You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
1.3 KiB

import { z } from 'zod'
const usernameField = z.string().trim().min(3, '用户名至少需要3个字符').max(30, '用户名最多30个字符')
const passwordField = z.string().min(8, '密码至少需要8个字符')
const confirmPasswordField = z.string()
const captchaTextField = z.string().min(1, '验证码不能为空')
const captchaTokenField = z.string().min(1, '验证码令牌不能为空')
const passwordRefine = (data: { password: string; confirmPassword: string }) =>
data.password === data.confirmPassword
export const registerSchema = z
.object({
username: usernameField,
password: passwordField,
confirmPassword: confirmPasswordField,
captchaToken: captchaTokenField,
captchaText: captchaTextField,
})
.refine(passwordRefine, {
message: '两次输入的密码不一致',
path: ['confirmPassword'],
})
/** Client-side schema: excludes captchaToken (managed by page shell) */
export const clientRegisterSchema = z
.object({
username: usernameField,
password: passwordField,
confirmPassword: confirmPasswordField,
captchaText: captchaTextField,
})
.refine(passwordRefine, {
message: '两次输入的密码不一致',
path: ['confirmPassword'],
})
export type RegisterInput = z.infer<typeof clientRegisterSchema>