Skip to content
masterclass Buddy

Zod · Method

.regex

Use z.string().regex() to validate a string against a regular expression. Parsing fails when the value does not match the pattern.

Last updated

Syntax

z.string().regex(pattern)

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • z.string()
  • z.string().min()
  • z.string().max()
  • z.stringFormat()

Source: Defining schemas | Zod. Checked 2026-11-03.