Zod schemas
chile-kit/zod has ready-made zod schemas for Chilean form fields. Each one validates the raw input and outputs the canonical value you store. zod is an optional peer dependency: only this subpath needs it, the rest of chile-kit stays dependency-free.
npm install chile-kit zod
import {
clpSchema,
communeCodeSchema,
personRutSchema,
phoneSchema,
regionCodeSchema,
rutSchema,
} from "chile-kit/zod";
rutSchema.parse("12.345.678-k"); // "12345678K"
personRutSchema.parse("1-9"); // throws: "RUT inválido" (body under 1.000.000)
phoneSchema.parse("9 1234 5678"); // "+56912345678"
clpSchema.parse(9990); // 9990 (whole, non-negative pesos)
regionCodeSchema.parse("RM"); // "13"
communeCodeSchema.parse("nunoa"); // "13120"
With react-hook-form
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { communeCodeSchema, personRutSchema, phoneSchema, regionCodeSchema } from "chile-kit/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
const checkout = z.object({
rut: personRutSchema,
phone: phoneSchema,
region: regionCodeSchema,
commune: communeCodeSchema,
});
export function Checkout() {
const { register, handleSubmit, formState: { errors } } = useForm<
z.input<typeof checkout>,
unknown,
z.output<typeof checkout>
>({ resolver: zodResolver(checkout) });
return (
<form onSubmit={handleSubmit((order) => console.log(order))}>
<input {...register("rut")} placeholder="12.345.678-5" />
{errors.rut && <p role="alert">{errors.rut.message}</p>}
{/* phone, region and commune the same way */}
</form>
);
}
The full form, with region and commune selects and IVA totals: examples/next/app/checkout-form.tsx.
Notes
- Messages are in Spanish ("RUT inválido", "Celular chileno inválido", "Comuna inválida"), for forms shown to people in Chile. Customize them with zod's error options.
- Tree-shaking. Every schema is marked pure: importing
rutSchemaalone does not ship the communes dataset. CI checks it. - Text inputs for amounts:
z.coerce.number().pipe(clpSchema). - zod 4 or newer.