【发布时间】:2021-01-23 00:26:18
【问题描述】:
我有一个带有自定义验证的架构。
const schema = new mongoose.Schema({
username: {
type: String,
required: true,
validate: {
validator: /^[a-zA-Z0-9_]{3,16}$/,
message: "Usernames must be 3 to 16 characters long and contain only alphanumeric characters and underscores (_)."
},
},
// ...other things
});
但是,当我输入无效的用户名时,验证消息如下所示:
User validation failed: username: Usernames must be 3 to 16 characters long and contain only alphanumeric characters and underscores (_).
如何去掉开头的字符串部分User validation failed: username: ?
【问题讨论】: