I'm trying to use the express validator to validate some user input on a form. However, when I type in the input and hit submit I get header errors and my messages are not displayed. I also have a problem where all the input is not getting the validation rules I set below. Any thoughts? (This is not the whole code it runs fine but I had to edit out some things.) If you need more info please reach out I have been trying to figure this out for a bit.
const express = require('express');
const { response } = require('express');
const { check, validationResult } = require('express-validator');
registerController =
([
check('fName')
.exists({ checkFalsy: true })
.isLength({ min: 3 })
.trim()
.escape()
.blacklist({ chars: '{};\\\'"<>,d' })
.withMessage('Name must be 3 letters long'),
check('lName')
.exists({ checkFalsy: true })
.isLength({ min: 3 })
.trim()
.escape()
.blacklist({ chars: '{};\\\'"<>,d' })
.withMessage('Name must be 3 letters long'),
check('email')
.exists({ checkFalsy: true })
.isEmail()
.normalizeEmail({ lowercase: true })
.blacklist({ chars: '{};\\\'"<>,' })
.withMessage('Please use a valid email'),
check('userName')
.exists({ checkFalsy: true })
.isLength({ min: 5 })
.trim()
.escape()
.blacklist({ chars: '{};\\\'"<>,' })
.withMessage('username must be at least 5 letters long'),
check('password1')
.exists({ checkFalsy: true })
.matches(/\d/)
.isLength({ min: 8 })
.trim()
.escape()
.blacklist({ chars: '{};\\\'"<>,' })
.withMessage('Password must be 8 characters long and contain numbers'),
check('password2')
.exists({ checkFalsy: true })
.matches(/\d/)
.isLength({ min: 8 })
.trim()
.escape()
.blacklist({ chars: '{};\\\'"<>,' })
.withMessage('Password must be 8 characters long and contain numbers'),
],
async (req, res) => {
const errors = validationResult(req);
let error = [];
if (!errors.isEmpty()) {
errors.array().forEach((err) => {
console.log(errors);
error.push({ message: err.msg });
});
res.render('loginRegister', { error });
}
});
from Recent Questions - Stack Overflow https://ift.tt/3rzGyi4
https://ift.tt/eA8V8J
No comments:
Post a Comment