Minimum age validation
Accept ages only from adulthood onward.
Zod · Module
.gte(value) adds an inclusive minimum constraint to a Zod number schema. Inputs below the supplied threshold fail validation, while the threshold and larger values are accepted.
.gte(value) adds an inclusive lower-bound check to a numeric Zod schema. Parsing succeeds when the input is at least the supplied value and fails with a validation error when it is smaller.
z.number().gte(value)| Name | Type | Description |
|---|---|---|
value | number | The inclusive minimum numeric value accepted by the schema. |
A Zod number schema with an inclusive lower-bound validation check.
.gte() as a refinement on a numeric schema, such as z.number().gte(18).import { z } from "zod";
const schema = z.number().gte(18);
console.log(schema.parse(21)); // 21
// schema.parse(17); // throws a ZodErrorCreates a number schema that accepts values greater than or equal to 18.
Accept ages only from adulthood onward.
Reject measurements below a permitted floor.
Validate counts that cannot be negative or too small.
.gte() method do?.gte() defines a minimum numeric value that is inclusive. A schema such as z.number().gte(18) accepts 18 and larger numbers, while smaller values fail validation.
Follow-up: How would you require a value strictly above 18? Use .gt(18) instead of .gte(18).
.gte() boundary inclusive?It is a numeric constraint applied to a number schema. The parsed input must satisfy the lower bound, otherwise parsing reports a validation failure.
Follow-up: How can the same lower bound be expressed with a range-style API? Use the numeric schema's minimum constraint when available in the documented API.
.gte() constraint?Yes. The method name represents greater-than-or-equal-to behavior, so the exact threshold is valid. This differs from .gt(), whose threshold is invalid.
Follow-up: What should be tested at minimum? Test one value below the threshold, the threshold itself, and one value above it.
z.numbergtlteltintpositivenonnegative