I'd like to check for a correct ObjectID to continue my code. I'am on NodeJS and I don't want to get the error:
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
Actually I got those tests:
if (!user.id || !user.id.match("/^[0-9a-fA-f]{24}$") || !typeof(user.id) === 'string') {
console.log("user id is required !")
return callback("user id is required !")
}
For string of 24 hex characters I got this regex :
!user.id.match("/^[0-9a-fA-f]{24}$")
And I am searching for check if it is a string of 12 bytes :
!typeof(user.id) === 'string'
How should I add the verification for the 12 bytes?
Any idea please?