Created
January 17, 2019 10:36
-
-
Save pablocattaneo/5eeaa895eba2ae34180e8204b3f093f2 to your computer and use it in GitHub Desktop.
#expressValidator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// String required | |
body('name') | |
.trim() | |
.not().isEmpty() | |
.withMessage('This field is required') | |
.isString() | |
.withMessage('This field must be an string') | |
// Email required | |
body('email') | |
.trim() | |
.isEmail() | |
.withMessage('Must be a valid email address') | |
.normalizeEmail() | |
// Example: | |
const express = require('express') | |
const adminController = require('../controllers/admin') | |
const { body } = require('express-validator/check') | |
const router = express.Router() | |
router.post('/insert', [ | |
body('name') | |
.trim() | |
.not().isEmpty() | |
.withMessage('This field is required') | |
.isString() | |
.withMessage('This field must be an string'), | |
body('lastName') | |
.trim() | |
.not().isEmpty() | |
.withMessage('This field is required') | |
.isString() | |
.withMessage('This field must be an string'), | |
body('email') | |
.trim() | |
.isEmail() | |
.withMessage('Must be a valid email address') | |
.normalizeEmail() | |
], adminController.createEmailsToSend) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment