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') ]; }
router.post( '/', [ check('username').isLength({min: 1}), check('domain').isIn([config.email.domain]) ], (req, res) => { const errors = validationResult(req) if (!errors.isEmpty()) { return res.render('login', { title: 'Login', username: req.body.username, domain: config.email.domain, userInputError: true }) } res.redirect(`/${req.body.username}@${req.body.domain}`) } )