title: Joi custom validation
body: <p>I'm using Joi to validate some data from user. I'm using it with module like this:</p>
  
  <pre><code>const Joi = require('joi')
  
  // User validation rules
  module.exports = {
    create: {
      body: {
        email: Joi.string().email().required(),
        password: Joi.string().min(6).max(128).required(),
        name: Joi.string().max(128).required()
      }
    },
    update: {
      body: {
        password: Joi.string().min(6).max(128).required(),
        name: Joi.string().max(128).required()
      }
    }
  }
  </code></pre>
  
  <p>and then in router I'm passing it as middleware:</p>
  
  <pre><code>router.post('/register', validator(create), userController.register)
  </code></pre>
  
  <p>For update I want to create custom validator with code like this:</p>
  
  <pre><code>const json = { 
    "email":"aa@aa.pl",
    "password":"someNewPass",
    "name":"John Smith",
    "activationKey":"123123",
    "active":false,
    "resetPasswordKey":"123123"
  }
  
  const forbiddenFields = ["email", "activationKey", "active", "resetPasswordKey"];
  
  const validate = (json, forbidden) =&gt; {
    for(let i = 0; i &lt; forbidden.length; i++) {
      if(json.hasOwnProperty(forbidden[i])) {
        return false;
      }
    }
    return true;
  }
  
  const isValid = validate(json, forbiddenFields)
  console.log('is json valid? ', isValid)
  </code></pre>
  
  <p>I found <a href="https://github.com/hapijs/joi/blob/v16.0.0-rc2/API.md#extendextension" rel="nofollow noreferrer">extend method in Joi API</a> but example is so confusing that I can not handle to create custom validation with my code.</p>