Skip to main content

Basic Usage

Type Signature

string | $ZodNumberParams
Optional error message (string) or configuration object

Important: NaN and Infinity

In Zod v4, z.number() does NOT accept NaN or Infinity by default:

Comparison Methods

.gt()

Greater than (exclusive).
number
required
Exclusive minimum value
string | $ZodCheckGreaterThanParams
Custom error message or params object

.gte() / .min()

Greater than or equal (inclusive). .min() is an alias for .gte().
number
required
Inclusive minimum value
string | $ZodCheckGreaterThanParams
Custom error message

.lt()

Less than (exclusive).
number
required
Exclusive maximum value
string | $ZodCheckLessThanParams
Custom error message

.lte() / .max()

Less than or equal (inclusive). .max() is an alias for .lte().
number
required
Inclusive maximum value
string | $ZodCheckLessThanParams
Custom error message

Sign Validations

.positive()

Requires number to be greater than zero.
string | $ZodCheckGreaterThanParams
Custom error message

.negative()

Requires number to be less than zero.
string | $ZodCheckLessThanParams
Custom error message

.nonnegative()

Requires number to be greater than or equal to zero.
string | $ZodCheckGreaterThanParams
Custom error message

.nonpositive()

Requires number to be less than or equal to zero.
string | $ZodCheckLessThanParams
Custom error message

Format Validations

.int() (Legacy)

Requires an integer value. Accepts only safe integers (Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER).
Consider using z.int() instead for a cleaner API.
string | $ZodCheckNumberFormatParams
Custom error message

.safe() (Deprecated)

Identical to .int(). Only accepts safe integers.

.finite() (Deprecated)

In v4, this is a no-op since z.number() doesn’t accept infinite values by default.

Multiple Of

.multipleOf() / .step()

Requires number to be a multiple of a given value. .step() is an alias.
number
required
The divisor (can be positive or negative)
string | $ZodCheckMultipleOfParams
Custom error message

Properties

.minValue

Returns the minimum value constraint, or null if not set.

.maxValue

Returns the maximum value constraint, or null if not set.

.isInt

Returns true if the schema requires an integer.

.isFinite

Always returns true in Zod v4 (numbers don’t accept infinite values).

.format

Returns the format string if set, or null.

Specialized Number Formats

Use these standalone constructors instead of methods on z.number():
  • z.int() - Safe integer
  • z.int32() - 32-bit signed integer
  • z.uint32() - 32-bit unsigned integer
  • z.float32() - 32-bit float
  • z.float64() - 64-bit float (standard JavaScript number)

Chaining

All methods return this, enabling chaining:

See Also