Skip to content

Instantly share code, notes, and snippets.

@kwiss
Created July 22, 2019 17:16
Show Gist options
  • Save kwiss/b5ea487d87bf78370be58d5bbb216944 to your computer and use it in GitHub Desktop.
Save kwiss/b5ea487d87bf78370be58d5bbb216944 to your computer and use it in GitHub Desktop.
express validator password
import { check } from 'express-validator/check';
app.post('/testPostPassword', [
check('password')
.exists()
.withMessage('Password should not be empty, minimum eight characters, at least one letter, one number and one special character')
.isLength({ min: 8 })
.withMessage('Password should not be empty, minimum eight characters, at least one letter, one number and one special character')
.matches(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/)
.withMessage('Password should not be empty, minimum eight characters, at least one letter, one number and one special character')
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment