-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor user command module and add form validation
- Loading branch information
1 parent
9c49969
commit 397f150
Showing
2 changed files
with
37 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { z } from 'zod'; | ||
|
||
export const SignUpFormSchema = z | ||
.object({ | ||
authId: z | ||
.string() | ||
.min(6, { | ||
message: '아이디는 6자 이상 20자 이하여야 합니다.', | ||
}) | ||
.max(20, { | ||
message: 'User ID must be at most 20 characters', | ||
}), | ||
password: z | ||
.string() | ||
.min(8, { message: '비밀번호는 8자 이상이어야 합니다.' }) | ||
.regex(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{8,}$/, { | ||
message: '비밀번호는 문자, 숫자, 특수문자(!@#$%^&*)를 포함해야 합니다.', | ||
}) | ||
.max(20, { message: '비밀번호는 20자 이하여야 합니다.' }), | ||
confirmPassword: z.string(), | ||
studentNumber: z.string().length(8, { message: '학번은 8자리여야 합니다.' }).startsWith('60', { | ||
message: '학번은 60으로 시작해야 합니다.', | ||
}), | ||
engLv: z.enum(['basic', 'ENG12', 'ENG34', 'bypass'], { | ||
invalid_type_error: '올바른 영어 레벨을 선택해주세요.', | ||
}), | ||
}) | ||
.superRefine(({ confirmPassword, password }, ctx) => { | ||
if (confirmPassword !== password) { | ||
ctx.addIssue({ | ||
code: 'custom', | ||
message: '비밀번호가 일치하지 않습니다.', | ||
path: ['confirmPassword'], | ||
}); | ||
} | ||
}); |