Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

celebrate node js

router.post('/',userMiddleWare, (req, res) => {});

const { celebrate, Joi, errors, Segments } = require("celebrate");
const userMiddleware = celebrate({
  body: Joi.object().keys({
    firstName: Joi.string().trim().min(2).max(30).required(),
    lastName: Joi.string().trim().min(2).max(30).required(),
    email: Joi.string()
      .trim()
      .min(2)
      .max(30)
      .required()
      .pattern(new RegExp(/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/)),
    password: Joi.string()
      .trim()
      .min(2)
      .max(30)
      .required()
      .pattern(
        new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[^A-Za-z0-9_])")
      ),
    role_id: Joi.string().trim().required(),
    position_id: Joi.string().trim().required(),
  }),
});

module.exports = { userMiddleware };
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #celebrate #node #js
ADD COMMENT
Topic
Name
7+1 =