diff --git a/objectid.js b/objectid.js index 1112244..a5e4f3f 100644 --- a/objectid.js +++ b/objectid.js @@ -132,31 +132,12 @@ ObjectID.createFromHexString = function(hexString) { ObjectID.isValid = function(id) { if (id == null) return false; - if (typeof id === 'number') { + try { + new ObjectID(id); return true; + } catch { + return false; } - - if (typeof id === 'string') { - return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id)); - } - - if (id instanceof ObjectID) { - return true; - } - - if (isBuffer(id)) { - return true; - } - - // Duck-Typing detection of ObjectId like objects - if ( - typeof id.toHexString === 'function' && - (id.id instanceof _Buffer || typeof id.id === 'string') - ) { - return id.id.length === 12 || (id.id.length === 24 && checkForHexRegExp.test(id.id)); - } - - return false; }; ObjectID.prototype = {