Basic Usage
Type Signature
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).
Exclusive minimum value
Custom error message or params object
.gte() / .min()
Greater than or equal (inclusive). .min() is an alias for .gte().
Inclusive minimum value
Custom error message
.lt()
Less than (exclusive).
Exclusive maximum value
Custom error message
.lte() / .max()
Less than or equal (inclusive). .max() is an alias for .lte().
Inclusive maximum value
Custom error message
Sign Validations
.positive()
Requires number to be greater than zero.
Custom error message
.negative()
Requires number to be less than zero.
Custom error message
.nonnegative()
Requires number to be greater than or equal to zero.
Custom error message
.nonpositive()
Requires number to be less than or equal to zero.
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.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.
The divisor (can be positive or negative)
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 onz.number():
z.int()- Safe integerz.int32()- 32-bit signed integerz.uint32()- 32-bit unsigned integerz.float32()- 32-bit floatz.float64()- 64-bit float (standard JavaScript number)
Chaining
All methods returnthis, enabling chaining:
See Also
- z.int() - Integer type
- Number Formats - Specialized numeric types
- z.bigint() - For integers outside safe range