admin管理员组文章数量:1345016
I am trying to validate min
and max
validations through model validations
last_name:{
type:Sequelize.STRING,
validate:{
notEmpty:{
args:true,
msg:"Last name required"
},
is:{
args:["^[a-z]+$",'i'],
msg:"Only letters allowed in last name"
},
max:{
args:32,
msg:"Maximum 32 characters allowed in last name"
},
min:{
args:4,
msg:"Minimum 4 characters required in last name"
}
}
}
But the min
and max
validators are never fired all other validators are working fine
I am trying to validate min
and max
validations through model validations
last_name:{
type:Sequelize.STRING,
validate:{
notEmpty:{
args:true,
msg:"Last name required"
},
is:{
args:["^[a-z]+$",'i'],
msg:"Only letters allowed in last name"
},
max:{
args:32,
msg:"Maximum 32 characters allowed in last name"
},
min:{
args:4,
msg:"Minimum 4 characters required in last name"
}
}
}
But the min
and max
validators are never fired all other validators are working fine
1 Answer
Reset to default 9You need to pass args an array
max:{
args:[32],
msg:"Maximum 32 characters allowed in last name"
},
min:{
args:[4],
msg:"Minimum 4 characters required in last name"
}
With use of len validator:
var Test = sequelize.define('test', {
name: {
type: Sequelize.STRING,
validate: {
notEmpty: {
args: true,
msg: "Required"
},
is: {
args: ["^[a-z]+$", 'i'],
msg: "Only letters allowed"
},
len: {
args: [4,32],
msg: "String length is not in this range"
}
}
},
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
}
}, {
tableName: 'test'
});
Test.create({name: "ab"}, function(error, result) {});
本文标签: javascriptSequelizejs min and max length validator are not workingStack Overflow
版权声明:本文标题:javascript - Sequelize.js min and max length validator are not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743774913a2536794.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论