title: Sequelize validation using regular expression
body: <p>I'm trying to use Regular expression in User Model to validate the password field. But it doesn't work for some reason. I've checked the sequelize docs and it says the validations should run automatically on <code>create</code>, <code>update</code> and <code>save</code>. <a href="https://sequelize.org/master/manual/models-definition.html#validations" rel="nofollow noreferrer">Link to Docs on validation.</a></p>
  
  <p>I have tried using <code>is</code> and a custom validator <code>checkPassword</code>. Both are not returning any error. Can someone please explain what am I doing wrong here?</p>
  
  <p>Here's is the my user model</p>
  
  <pre class="lang-js prettyprint-override"><code>import { CustomError } from '../../utils/error';
  
  module.exports = (sequelize, DataTypes) =&gt; {
    const User = sequelize.define(
      'User',
      {
        firstName: DataTypes.STRING,
        lastName: DataTypes.STRING,
        email: {
          allowNull: false,
          unique: true,
          type: DataTypes.STRING,
          validate: {
            isEmail: true
          }
        },
        password: {
          allowNull: false,
          type: DataTypes.STRING,
          validate: {
            checkPassword(value) {
              if (
                !/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&amp;]).{8,}$/.test(
                  value
                )
              ) {
                throw new CustomError(400, 'Provide a valid password!');
              }
            },
  
            is: {
              args: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[#$^+=!*()@%&amp;]).{8,}$/,
              msg:
                'The password must contain atleast 8 characters including at least 1 uppercase, 1 lowercase and one digit.'
            }
          }
        }
      },
      {}
    );
    User.associate = function(models) {
      User.hasMany(models.Post, {
        foreignKeyConstraint: true,
        foreignKey: 'userId'
      });
      User.hasMany(models.Comment, {
        foreignKey: 'userId',
        foreignKeyConstraint: true
      });
    };
    return User;
  }
  
  </code></pre>