const { body, validationResult } = require("express-validator");

module.exports = validateUserInput = [
    body("email").isEmail().withMessage("Invalid Email Format"),

    body("phone").matches(/^\+?[1-9]\d{1,14}$/).withMessage("Invalid Phone Number"),

    (req, res, next) => {
        const errors = validationResult(req);
        if(!errors.isEmpty()) {
            return res.status(400).json({errors: errors.array()});
        }
        next();
    }
]
