Creating custom validation methods
Sequelize gives us the ability to create our own validations simply by adding a function to the validate
parameter on attributes or within the validate
parameter on the model’s options (the second input parameter for the Model.init()
function).
If we wanted to create our own validation to restrict our users from using password
as a password, we would write a solution similar to this:
MyModel.init({ password: { type: DataTypes.STRING, validate: { notLiteralPassword(value) { if (value === 'password') { throw new Error("Your password cannot be 'password&apos...