A Joi extension for validating MongoDB ObjectId strings. Version 4.0.2 works with Joi v17+ (Hapi ecosystem). Validates that a value is a 24-character hex string. Lightweight, zero extra dependencies beyond Joi. Not needed for mongoose schemas but useful for plain Joi validation.
npm install joi-objectidNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to extend Joi with the ObjectId validator and use it in a schema.
Use @hapi/joi v17+ or switch to joi-objectid v3.x for Joi v16.
Always call require('joi-objectid')(Joi) and assign Joi.objectId.Switch to import from @hapi/joi.
This is by design; use mongodb's ObjectID constructor for deeper validation.
Add a declaration file that augments @hapi/joi's StringSchema.
Use Joi.objectId() (no hyphen).
Ensure you call require('joi-objectid')(Joi) and assign to Joi.objectId, and use @hapi/joi v17+.Ensure the value is exactly 24 hex characters [0-9a-fA-F].
Install @hapi/joi: npm install @hapi/joi
Pass the Joi instance: const objectId = require('joi-objectid')(Joi);