Enforce Data Validation on Models in Sequelize

Sequelize·1 min read·Jan 1, 2025

In addition to constraints, Sequelize provides a list of built-in model validators implemented by the validator library, that allow you check and validate the data format of columns through the validate property:

{  <column>: {    type: <type>,    validate: {      <validator>: <value>,      ...    }  }}

Note: These validators are only executed upon CREATE and UPDATE operations.

Validate numbers

To check numbers, you can use:

  • isNumeric: true: to only allow numbers.
  • isInt: true: to check for valid integers.