Answers for "express validator is required"

1

how to validate express js form

// Validation rules.var loginValidate = [  check('username', 'Username Must Be an Email Address').isEmail(),  check('password').isLength({ min: 8 })  .withMessage('Password Must Be at Least 8 Characters')  .matches('[0-9]').withMessage('Password Must Contain a Number')  .matches('[A-Z]').withMessage('Password Must Contain an Uppercase Letter')];// Process user input.app.post('/login', loginValidate, (req, res) => {  // Insert Login Code Here});
Posted by: Guest on June-02-2021
0

custom validator express validator

body("thumbnail_file").custom(async (value, { req }) => {
  const thumbnailFile = req.files && req.files.thumbnail_file;
  if (!thumbnailFile) {
    return true;
  } else if (Array.isArray(thumbnailFile)) {
    throw new Error("Only one thumbnail file is allowed.");
  }
  if (
    thumbnailFile.mimetype !== "image/png" &&
    thumbnailFile.mimetype !== "image/jpg" &&
    thumbnailFile.mimetype !== "image/jpeg"
  ) {
    throw new Error(
      "Only .png, .jpg and .jpeg image formats are allowed for thumbnail file."
    );
  }
}),
Posted by: Guest on April-14-2022

Code answers related to "express validator is required"

Browse Popular Code Answers by Language