Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import { z } from 'zod'; export const jpPostalRe = /^(\d{3}-?\d{4})$/; /** 空文字を undefined に寄せる(任意入力フィールドに便利) */ export const optionalEmptyToUndef = () => z.string().optional().or(z.literal('').transform(() => undefined)); /** 必須の数値(coerce + int / positive は呼び出し側で付け外し可) */ export function coerceIntRequired(msgs: { required: string; type: string; }) { return z.coerce.number({ required_error: msgs.required, invalid_type_error: msgs.type, }); } /** 長さ系の薄いラッパ(好みで使う) */ export const stringMax = (max: number, message: string) => z.string().max(max, message); export const stringMaxOptional = (max: number, message: string) => z.string().max(max, message).optional(); /** 2桁の国コード(共通化しておくと楽) */ export const countryCode2 = (requiredMsg: string, lenMsg: string) => z.string({ required_error: requiredMsg }) .length(2, lenMsg) .transform((s) => s.toUpperCase()); |