Download src/lib/validations/code.ts from HonzaH/Letschat: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/lib/validations/code.ts
- Command line
-
hf download hf://spaces/HonzaH/Letschat/src/lib/validations/code.ts
-
curl -L -o code.ts https://huggingface.co/spaces/HonzaH/Letschat/resolve/main/src/lib/validations/code.ts
1.11 kB
| import { z } from 'zod' | |
| export const codeEntrySchema = z.object({ | |
| code: z.string() | |
| .length(5, 'Kód musí mít přesně 5 znaků') | |
| .regex(/^[A-Z0-9]{5}$/, 'Kód může obsahovat pouze písmena A-Z a číslice 0-9') | |
| }) | |
| export const pinEntrySchema = z.object({ | |
| pin: z.string() | |
| .length(5, 'PIN musí mít přesně 5 číslic') | |
| .regex(/^[0-9]{5}$/, 'PIN může obsahovat pouze číslice 0-9') | |
| }) | |
| export const codeWithPinSchema = z.object({ | |
| code: z.string().length(5).regex(/^[A-Z0-9]{5}$/), | |
| // Allow empty string (treat as no PIN) by preprocessing empty strings to undefined, | |
| // otherwise validate exactly 5 digits when provided. | |
| pin: z.preprocess( | |
| (val) => (typeof val === 'string' && val.trim() === '') ? undefined : val, | |
| z.string().length(5, 'PIN musí mít přesně 5 číslic').regex(/^[0-9]{5}$/, 'PIN může obsahovat pouze číslice 0-9').optional() | |
| ) | |
| }) | |
| export type CodeEntryForm = z.infer<typeof codeEntrySchema> | |
| export type PinEntryForm = z.infer<typeof pinEntrySchema> | |
| export type CodeWithPinForm = z.infer<typeof codeWithPinSchema> |