Reputation: 490
Is there a simple built in way to check if a string is a valid ObjectId? I know if I try to construct an ObjectId from an invalid string it throws an exception, is there a way to circumvent the try-catch block?
One possible way would be to check against this regex: ^[0-9a-b]{48}$
Is there something more elegant?
Upvotes: 0
Views: 441