UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

23 lines (22 loc) 807 B
import { z } from 'zod'; import { buildCommonSchema } from '../../registry/validation'; import { POSTCODE_REGEX } from '../postcode/constants'; // Constraints taken from the BRK API (apart from postcode which comes from our postcode component) const addressNLSchema = z.object({ postcode: z.string().regex(new RegExp(POSTCODE_REGEX)).optional(), houseNumber: z .string() .regex(/^\d{1,5}$/) .optional(), houseLetter: z .string() .regex(/^[a-zA-Z]$/) .optional(), houseNumberAddition: z .string() .regex(/^([a-z,A-Z,0-9]){1,4}$/) .optional(), }); const defaultValueSchema = z.object({ defaultValue: addressNLSchema }); const schema = ({ intl }) => buildCommonSchema(intl).and(defaultValueSchema); export default schema;