body("isbn", "ISBN must not be empty").isLength({ min: 1 }).trim().custom((value,{req}) => { return Book.findOne({isbn : value,user: req.user._id}).then(book => { if (book) { return Promise.reject("Book already exist with this ISBN no."); } }); })
body('confirm') .custom((value, {req}) => { if (value !== req.body.password) { throw new Error('Password must be symbols') } return true }) .trim()
router.post('/reset/:token', [ check('password').not().isEmpty().isLength({min: 6}).withMessage('Must be at least 6 chars long'), check('confirmPassword', 'Passwords do not match').custom((value, {req}) => (value === req.body.password)), ], validate, Password.resetPassword);
router.post('/register', upload.single('profileimage'), [ check('email', 'Email is not valid').isEmail(), check('username', 'Username field is required').not().isEmpty(), check('password', 'Password field is required').not().isEmpty(), check('password').isLength({ min: 3 }).withMessage('Password must be at least 3 chars long'), check('password').matches(/\d/).withMessage('Password must contain a number'), check('password2').custom((value, {req}) => { //custom validator if(value!==req.body.password) { throw new Error('Passwords doesn\'t match'); } return true; }) ], userController.register);
.findById(req.user._id) .select(['password']) .exec() .matches(/\d/), body('password', `New password and current password are identical`) .custom((password, { req }) => password !== req.body.old_password), body('password_confirmation', `Passwords don't match`) .exists() .custom((password_confirmation, { req }) => password_confirmation === req.body.password), validateRequest, ],
body('repeat', 'Passwords does not match') .exists() .custom((value, { req }) => value === req.body.password) ], async (req, res, next) => {
body('confirmPassword') .custom((value, {req}) => { const password = req.body.password; if(value !== password) { throw new Error('Passwords have to match!');