如何使用锚,帆的validation系统?

我试图使用Sails,但我不能使用模型validation,任何人都可以帮助我吗?

validation添加到模型上的属性对象。 您可以在以下位置find可用的validation列表: Sails Wiki – Models 。 只要您提交要写入数据存储区的数据,就会运行它们。 因此, create Waterline将validation您提交的所有属性, update它将validation您尝试更改的属性。

validation示例模型如下所示:

 module.exports = { attributes: { firstName: { type: 'string', minLength: 3, required: true }, lastName: { type: 'string', minLength: 3, required: true }, email: { // types can be a validation type and will be converted to a string // when saved type: 'email', required: true }, sex: { type: 'string', in: ['male', 'female'] }, favoriteColor: { type: 'string', defaultsTo: 'blue' }, age: { type: 'integer', min: 18 } } }