Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pablocattaneo/5eeaa895eba2ae34180e8204b3f093f2 to your computer and use it in GitHub Desktop.
Save pablocattaneo/5eeaa895eba2ae34180e8204b3f093f2 to your computer and use it in GitHub Desktop.
#expressValidator
// 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