Big integer input validation
Validate IDs, counters, timestamps, or other values represented as JavaScript bigint.
Zod · Module
z.bigint() creates a Zod schema for validating JavaScript bigint values. It supports comparison, sign, and divisibility constraints.
z.bigint() creates a schema that accepts JavaScript bigint values. Chain bigint-specific checks such as comparisons, sign constraints, and divisibility; use z.coerce.bigint() instead when the input must first be converted to bigint.
z.bigint()A Zod bigint schema.
z.bigint() to create a schema whose input type is JavaScript bigint.positive() requires a value above zero; the documentation identifies gt(0n) as its alias.z.bigint() validates bigint inputs; it does not perform the coercion described by the documentation. Choose z.coerce.bigint() when conversion is required.import { z } from "zod";
const schema = z.bigint().positive().multipleOf(5n);
console.log(schema.parse(25n)); // 25n
// schema.parse(22n); // throws: not a multiple of 5
Validates a positive bigint divisible by 5.
Validate IDs, counters, timestamps, or other values represented as JavaScript bigint.
Enforce a minimum, maximum, sign, or divisibility rule on a bigint.
Accept coercible external input when conversion to bigint is desired.
z.bigint() validate?z.bigint() is a Zod schema for validating JavaScript bigint values. It can be refined with bigint-specific checks such as gt, positive, and multipleOf.
Follow-up: How would you accept a string such as "123"? Use z.coerce.bigint(), or build a codec when an explicit bidirectional conversion is needed.
gte(5n) requires a value greater than or equal to 5n; the documentation lists .min(5n) as its alias. Similarly, lte(5n) is the alias-bearing upper-bound check corresponding to .max(5n).
Follow-up: How would you require a strict lower bound? Use gt(5n) rather than gte(5n).
Use positive() or nonnegative() for sign requirements, and negative() or nonpositive() for negative-side requirements. For divisibility, use multipleOf(5n); the documentation lists .step(5n) as its alias.
Follow-up: How could you combine sign and divisibility constraints? Chain both methods, such as z.bigint().positive().multipleOf(5n).
z.coerce.bigintz.codecz.int