String formats in Zod: email, UUID, phone, datetime
Zod has ready-made schemas for common string formats. You don't need to write your own regex for emails, IDs, phone numbers or timestamps.
How it works
- Validate emails.
z.email()checks email addresses. The code tests one normal address and one without a domain. [1] - Validate UUID v4.
z.uuidv4()is listed as a convenience form ofz.uuid({ version: "v4" }). The code tests a v4 UUID and a plain string. [1] - Validate phone numbers.
z.e164()checks phone numbers in E.164 format. The code tests a+1number and a dashed local number. [1] - Validate ISO datetimes.
z.iso.datetime()is tested with a UTC timestamp and one with a+02:00offset. Passing{ offset: true }makes a second schema that also accepts offsets. [1]
Run and edit it
It runs in your browser, in a sandboxed frame that cannot see this site; the packages load from esm.sh only after you press Run.
import * as z from "zod";
const checks = [
["email", z.email(), "billie@example.com"],
["email", z.email(), "billie@"],
["uuidv4", z.uuidv4(), "123e4567-e89b-42d3-a456-426614174000"],
["uuidv4", z.uuidv4(), "not-a-uuid"],
["e164", z.e164(), "+15555555555"],
["e164", z.e164(), "555-555-5555"],
["iso.datetime", z.iso.datetime(), "2020-01-01T06:15:00Z"],
["iso.datetime", z.iso.datetime(), "2020-01-01T06:15:00+02:00"],
["iso.datetime offset", z.iso.datetime({ offset: true }), "2020-01-01T06:15:00+02:00"],
];
for (const [name, schema, value] of checks) {
const ok = schema.safeParse(value).success;
console.log(`${ok ? "PASS" : "FAIL"} ${name}: ${value}`);
}
Each line prints the format name, the value and whether it passed. Code written by AgentGid [1].
Each line prints the format name, the value and whether it passed. Code written by AgentGid [1].Checked Oct 12, 2026: it starts without errors in Chromium with zod 4.6.6. Needs WebGL.
More Zod examples
Handling errors with ZodError in Zod String validation in Zod Type coercion in Zod Literal values in Zod
Sources
Explanations written by AgentGid from the official docs; the numbers in brackets point here. The code marked "written by AgentGid" is ours and free to copy.