Registry / database / mongoose-valid8

mongoose-valid8

JSON →
library1.7.1jsnpmunverified

A Mongoose plugin providing additional schema validations for common string formats (email, UUID, credit card, IP, MAC address, etc.). Current stable version is 1.7.1, released in 2021 and maintained intermittently. It works by importing the plugin once and then using validation flags directly in schema definitions (e.g., `email: true`). Compared to alternatives like `mongoose-validator`, this package offers a simpler declarative syntax without custom validator functions.

npm install mongoose-valid8
INSTALL
IMPORT
SIG · MONGOOSE-VALID8
M
mongoose-valid8
databasejavascriptv1.7.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mongoose-valid8 (side-effect import)
import 'mongoose-valid8'
import mongooseValid8 from 'mongoose-valid8'
The package must be imported as a side-effect only (no default export). It patches Mongoose's Schema types globally.
No named exports
import 'mongoose-valid8'
import { email } from 'mongoose-valid8'
There are no named exports; all validations are applied via schema options (e.g., `email: true`).
CommonJS require
require('mongoose-valid8')
const valid8 = require('mongoose-valid8')
For CommonJS environments, require the module without assigning to a variable.

Quickly validate email, IP, and credit card using schema flags with async validation.

import mongoose from 'mongoose'; import 'mongoose-valid8'; const userSchema = new mongoose.Schema({ email: { type: String, email: true, required: true }, ip: { type: String, ip: true }, creditCard: { type: String, creditcard: true }, }); const User = mongoose.model('User', userSchema); const user = new User({ email: 'invalid', ip: 'not-an-ip', creditCard: '1234', }); user.validate(err => { console.log(err); // ValidationError with three failing validations });
Debug
Known issues
breakingMongoose peer dependency changed from ^5.7 to >=6.0.7 between versions 1.6.x and 1.7.x
fix
Upgrade Mongoose to 6.0.7 or later.
affects: >=1.7.0
gotchaValidations are only applied during `validate()` or `save()`, not on document creation or assignment.
fix
Call `validate()` or rely on `save()` to trigger validation.
affects: >=1.0.0
brokenThe `phone` validation accepts an object (e.g., {locale: 'en-US'}) but is not properly documented; using `phone: true` may not work as expected.
fix
Use `phone: {locale: 'en-US'}` or check the source for valid options.
affects: >=1.7.0
deprecatedThe `alphanumeric` flag is misspelled as `aphanumeric` in the README; the actual key may be `aphanumeric` or `alphanumeric` depending on version.
fix
Check the source: use `aphanumeric: true` (as in README) or `alphanumeric` if fixed in later versions.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'mongoose-valid8'
Package not installed or missing peer dependency mongoose.
fix
Run `npm install mongoose mongoose-valid8`.
ValidationError: Path `email` is not valid: email validator failed
The email value does not pass the built-in email validation.
fix
Provide a valid email address (e.g., 'user@example.com').
Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
Attempting to use `uuid: true` with an invalid UUID string.
fix
Provide a valid UUID v4 string (e.g., '550e8400-e29b-41d4-a716-446655440000').
MongooseError: `mongoose-valid8` is not compatible with your Mongoose version. Minimum required Mongoose version is 6.0.7
Installed Mongoose is older than 6.0.7.
fix
Update Mongoose: `npm install mongoose@6`.
Upgrade
Version history
1.7.1latest on npm
Audit
Dependencies
mongooserequiredpeer dependency; plugin requires Mongoose >=6.0.7
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources
mongoose-valid8 — npm install mongoose-valid8 · libregistry