https://github.com/maevadevs/mongoose-custom-validators
NPM: A collection of custom validators for Mongoose that complements Mongoose validators and the validator package.
https://github.com/maevadevs/mongoose-custom-validators
criterias isvalidpassword mongoose mongoose-schema
Last synced: 6 months ago
JSON representation
NPM: A collection of custom validators for Mongoose that complements Mongoose validators and the validator package.
- Host: GitHub
- URL: https://github.com/maevadevs/mongoose-custom-validators
- Owner: maevadevs
- License: mit
- Created: 2018-04-05T00:43:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-05T02:31:21.000Z (about 8 years ago)
- Last Synced: 2025-10-19T18:51:05.617Z (8 months ago)
- Topics: criterias, isvalidpassword, mongoose, mongoose-schema
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
# Custom Validators for Mongoose Schema
This repository contains some custom validators for Mongoose Schema. It complements the validators that are already found within [Mongoose](http://mongoosejs.com/docs/validation.html) itself *AND* the [`validator`](https://www.npmjs.com/package/validator) package.
## Installation
npm i mongoose-custom-validators --save
or
yarn add mongoose-custom-validators
## List of Custom Validators
- [isValidPassword](#isValidPassword)
#### Signature: `(String, require = defaultRequire) => Boolean`
Validates password string against the requirements properties. By default, we opt for a strong password that must meet the following criterias:
defaultRequire = {
minlength: 10, // At least 10 characters long (optional)
uppercase: true, // Have at least 1 uppercase character
lowercase: true, // Have at least 1 lowercase character
number: true, // Have at least 1 number
nonalpha: true // Have at least 1 Nonalpha character
}
#### Usage
const { isValidPassword } = require('mongoose-custom-validators')
To override some or all of the defaults, pass in an object with the criterias properties to override. **Non-overriden criterias will be using the `defaultRequire`.** The only acceptable properties are the ones listed under the `defaultRequire`
If using `defaultRequire`, simply pass the function as the validator
validate: {
validator: isValidPassword,
message: 'Password must have at least: 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character.'
}
If using with custom `userRequire`, pass validator through an anonymous function that takes the password string
validate: {
validator: (str) => isValidPassword(str, { uppercase: false }),
message: 'Password must have at least: 1 lowercase letter, 1 number, and 1 special character.'
}