-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformValidation.ts
More file actions
45 lines (39 loc) · 1.87 KB
/
formValidation.ts
File metadata and controls
45 lines (39 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { z } from 'zod';
import { zodResolver } from '@hookform/resolvers/zod';
export const formSchema = z.object({
name: z.string().min(2, '이름은 최소 두 글자 이상이어야 합니다.').max(10, '이름은 최대 10자까지 가능합니다.'),
email: z
.string()
.email('올바른 이메일 형식이어야 합니다.')
.regex(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/, '올바른 이메일 형식이어야 합니다.'),
phone: z
.string()
.regex(/^[0-9]{3}-[0-9]{3,4}-[0-9]{4}$/, '연락처는 휴대전화 번호 형식(예: 010-1234-5678)이어야 합니다.'),
});
export const organizerFormSchema = formSchema.pick({ email: true, phone: true });
export const eventTitleSchema = z.object({
title: z.string().min(2, '제목은 최소 두 글자 이상이어야 합니다.'),
});
export const hostCreationSchema = z.object({
hostChannelName: z.string().min(2, '채널 이름은 최소 두 글자 이상이어야 합니다.'),
hostEmail: z.string().email('올바른 이메일 형식이어야 합니다.'),
channelDescription: z.string().min(5, '채널 설명은 최소 두 글자 이상이어야 합니다.'),
});
export const myPageSchema = formSchema.pick({ name: true, phone: true });
export const hostInfoSchema = formSchema.pick({ email: true });
export type FormData = z.infer<typeof formSchema>;
export type OrganizerFormData = z.infer<typeof organizerFormSchema>;
export type EventTitleFormData = z.infer<typeof eventTitleSchema>;
export type HostCreationFormData = z.infer<typeof hostCreationSchema>;
export const zodValidation = {
resolver: zodResolver(formSchema),
};
export const organizerZodValidation = {
resolver: zodResolver(organizerFormSchema),
};
export const eventTitleZodValidation = {
resolver: zodResolver(eventTitleSchema),
};
export const hostCreationZodValidation = {
resolver: zodResolver(hostCreationSchema),
};