body("vehicle", "If you have a vehicle please provide a its manufacture year") .custom(a => { if (a && "year" in a) { const currentYear = new Date().getFullYear(); // comparing year with age of the oldest and the most recent vehicule if (a.year === parseInt(a.year, 10) && (a.year >= 1885) && (a.year <= (currentYear + 1))) { return true; } else return false; } else return true; })
function validationRules() { return [ check('first_name').not().isEmpty().withMessage('First name is required'), check('last_name').not().isEmpty().withMessage('Last name is required'), check('gender').not().isEmpty().withMessage('Gender is required').isIn(['M', 'F']), check('date_of_birth').toDate().optional({ checkFalsy: true }), check('mobile').optional({ checkFalsy: true }).isInt(), check('address').optional({ checkFalsy: true, nullable: true }).isLength({ min: 10 }).withMessage('Please enter minimum 10 characters'), check('email').optional({ checkFalsy: true, nullable: true }).isEmail().withMessage('Please enter valid email') ]; }
check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
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);
body("house", "The attribute ownership status should can be \"owned\" or \"mortgaged\"") .custom(a => { if (a && "ownership_status" in a) { if (a.ownership_status === "owned" || a.ownership_status === "mortgaged") { return true; } else return false; } else return true; })
check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlGitHub') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')
check('urlTwitter') .optional() .custom((v) => (v === '' ? true : validator.isURL(v))) .withMessage('NOT_A_VALID_URL')