给定以下示例POST正文:
User = {
email: string; //required, email
password: string; //required, min length 8
profile: {
firstName: string; //required
lastName: string; //required
gender: Gender; //required, enum (M/F)
}
}
我如何定义一个表达式ValidationSchema
来验证嵌套Profile
对象及其内部的道具User
userValidatorSchema: ValidationSchema = {
email: {
isEmail: {}
},
password: {
exists: {
options: {checkNull: true},
errorMessage: 'Null value'
},
isEmpty: {
negated: true,
errorMessage: 'Empty string'
}
}
//Profile validation??
Express-validator文档使Express-validator看起来像不可能。如果是这样,那么更通用的快递验证器是什么?
您是否尝试过这种方法:
// Profile validation
profile: {
optional: false
},
'profile.firstName': {
notEmpty: true,
optional: false
}
// ...others
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句