0.1.3 • Published 10 years ago

validity-string-represents-mongodb-objectid v0.1.3

Weekly downloads
2
License
-
Repository
github
Last release
10 years ago

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