File size: 1,112 Bytes
9853b20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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>