Exclusive maximum validation
Reject an input at or above a configured ceiling, such as a quantity that must remain below a maximum.
Zod · Module
z.number().lt(value) validates finite numbers that are strictly less than value. It adds an exclusive upper bound to a Zod number schema.
.lt(value) adds an exclusive upper-bound check to a number schema. The schema first validates that the input is a finite number, then accepts it only when it is strictly less than the supplied limit.
z.number().lt(value)| Name | Type | Description |
|---|---|---|
value | number | Exclusive upper-bound threshold that the validated number must be strictly less than. |
A Zod number schema that accepts finite numbers strictly less than the supplied threshold.
.lt() is a number-specific constraint and should be chained from z.number()..lt(limit) narrows that set to values below the limit..lte() is the related inclusive upper-bound method; use it when the threshold itself should pass.import { z } from "zod";
const schema = z.number().lt(10);
console.log(schema.safeParse(9).success); // true
console.log(schema.safeParse(10).success); // falseCreates a number schema that accepts values below 10 and rejects 10 or greater.
Reject an input at or above a configured ceiling, such as a quantity that must remain below a maximum.
Validate a numeric field whose boundary value is intentionally invalid, such as a zero-based index below a collection length.
.lt(5) validate?z.number().lt(5) accepts finite numbers strictly smaller than 5. The boundary value 5 fails because the comparison is exclusive.
Follow-up: How would you allow 5 as well? Use z.number().lte(5), which applies an inclusive upper bound.
.lt() in a Zod schema?It is chained after z.number() and receives the maximum threshold as its argument: z.number().lt(5). The resulting schema remains a number schema with the additional upper-bound constraint.
Follow-up: What happens to non-numbers? They fail the underlying z.number() validation before the limit comparison is relevant.
.lt() differ from the related number constraints?The documented number-specific methods include .gt(), .gte(), .lt(), and .lte(). Among these, .lt() is the strict upper-bound validator, while .lte() permits the threshold itself.
Follow-up: Which documented aliases correspond to inclusive bounds? .gte() is aliased by .min(), and .lte() is aliased by .max().
z.number()z.number().gt()z.number().gte()z.number().lte()z.number().positive()