Basic numeric validation
Validate request, configuration, or form fields that must contain finite numeric values.
Zod · Type Alias
ZodNumber is the schema type created by z.number(). It validates finite JavaScript numbers and supports additional numeric constraints such as bounds, integer checks, signs, and multiples.
ZodNumber is the schema produced by z.number(). It accepts finite JavaScript numbers and can be combined with numeric constraints such as minimum, maximum, integer, positivity, and multiples; parsing rejects values that do not satisfy the schema.
z.number()A ZodNumber schema that validates finite numbers and supports numeric constraints.
import { z } from "zod";
const score = z.number().min(0).max(100);
console.log(score.parse(87.5));
Creates a finite-number schema constrained to the inclusive range 0 through 100, then parses a valid decimal.
Validate request, configuration, or form fields that must contain finite numeric values.
Enforce ranges, increments, integer requirements, or sign restrictions on domain values.
Validate object keys represented as numeric strings while applying numeric constraints.
z.number() creates a schema for JavaScript numbers. It accepts finite numbers, while NaN and Infinity fail parsing.
Follow-up: How would you restrict the accepted range? Chain constraints such as .min(0) and .max(100) on the number schema.
Use methods such as .min(), .max(), and .multipleOf() for numeric bounds and divisibility. The documentation also lists integer and sign-related constraints.
Follow-up: How would you validate only positive whole numbers? Use z.number().int().positive(), or the dedicated integer format when appropriate.
A Zod number schema can be used as a record key. Zod validates the key as a valid numeric string and applies numerical constraints such as min, max, and step.
Follow-up: Why is this behavior useful? It lets record-key validation mirror TypeScript's treatment of numeric keys while still enforcing the schema's constraints.
z.int()z.float32()z.float64()z.record()