Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Zod · Type Alias

ZodNumber

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.

How it works

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.

Syntax

z.number()

Returns

A ZodNumber schema that validates finite numbers and supports numeric constraints.

Key points

  • Call z.number() to create the numeric schema.
  • The unmodified schema accepts finite numeric values.
  • Decimal values are valid when they are finite.
  • NaN does not pass number parsing.
  • Positive infinity is rejected.
  • Numeric schemas support extra checks for bounds, increments, and related restrictions.

Common mistakes

  • The base number schema accepts finite values, so NaN and both infinities are rejected.
  • When used as a record key, numeric-looking keys are validated as numeric strings and their numerical constraints are applied.

Example: Validate a bounded number

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.

When to use it

Basic numeric validation

Validate request, configuration, or form fields that must contain finite numeric values.

Constrained numeric fields

Enforce ranges, increments, integer requirements, or sign restrictions on domain values.

Numeric record keys

Validate object keys represented as numeric strings while applying numeric constraints.

Interview questions

QWhat does z.number() validate?

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.

QHow can a Zod number be constrained?

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.

QWhat happens when a number schema is used as a record key?

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()

Source: Defining schemas. Checked 2026-10-15.