isValid()

Static method that validates whether a string is a properly formatted ObjectId hex string.

Usage

import { ObjectId } from 'funtool';

ObjectId.isValid('5f1d7f3b1c9d440000000000'); // true
ObjectId.isValid('invalid'); // false

Signature

static isValid(hex: string): boolean

Parameters

  • hex: The string to validate

Return Value

Returns true if the string is a valid 24-character hex string, false otherwise.

Notes

  • Checks length and hex character validity
  • Does not verify uniqueness
  • Useful for input validation
  • Matches MongoDB validation rules