validity-string-represents-mongodb-objectid
v0.1.3
Published
Validity style validator to ensure a property represents a mongodb object id
Downloads
3
Readme
validity-string-represents-mongodb-objectid
Validity style validator to ensure a property is an Object ID.
Installation
npm install validity-string-represents-mongodb-objectid
Usage
Below is a simple example for usage with schemata:
var validity = require('validity')
, schemata = require('schemata')
, stringRepresentsObjectId = require('validity-string-represents-mongodb-objectid')
var schema = schemata(
{ linkedObjectId:
{ type: String
, validators:
{ all: [stringRepresentsObjectId()]
}
}
, otherObjectId:
{ type: String
}
})
schema.validate({ linkedObjectId: 'noidhere', linkedObjectId: 'notanid' }, function (error, valid) {
// Show the error
console.log(valid)
})
Credits
Tom Gallacher follow me on twitter @tomgco
Licence
Licensed under the MIT License