Skip to main content
AllDevToolsHub
Back to all patterns

MongoDB ObjectId

Validation

Validates a MongoDB ObjectId, 24 hex characters.

/^[0-9a-fA-F]{24}$/

How it works

ObjectId is a 12-byte identifier (timestamp + machine + pid + counter), commonly displayed as 24 hex characters. Used as the default _id type.

Test Cases

Should Match

  • 507f1f77bcf86cd799439011
  • 5DBFF32E1F54E72CC8E3F8C9

Should NOT Match

  • 507f1f77bcf86cd79943901
  • not-an-objectid
  • 507f1f77bcf86cd799439011g

Quick Summary

Matches a 24-character hex string, the canonical text representation of a MongoDB ObjectId.