diff --git a/src/schemas/index.ts b/src/schemas/index.ts index 8bcdb3b..94817ce 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -10,9 +10,19 @@ function buildZodSchema(backendType: BackendType): z.ZodObject = {}; for (const field of fields) { - shape[field.key] = field.required + let schema: z.ZodTypeAny = field.required ? z.string().min(1, `${field.label} is required`) - : z.string().optional(); + : z.string(); + + if (field.validate) { + schema = (schema as z.ZodString).regex(field.validate.regex, field.validate.message); + } + + if (!field.required) { + schema = (schema as z.ZodString).optional(); + } + + shape[field.key] = schema; } return z.object(shape); }