我有下面的模型,我想要cartaoCidadao有正好8个数字。正则表达式不允许小于8,但允许大于8。出了什么问题?我还希望密码至少包含8个字符。
ar userSchema = new Schema({
cartaoCidadao: {
type: String,
required: [true, "cartaoCidadao is a required field"],
index: true,
unique: true,
match: /[0-9]{8}/,
},
password: { type: String, required: ["password is a required field"] },
role: { type: String, enum: ["Admin", "Technical", "User"] },
estado: { type: String, enum: ["Infetado", "Suspeito", "Não Infetado"] },
});
答案 0 :(得分:1)
尝试一下
{
cartaoCidadao: {
//Match exactly 8 digits
match: /^[0-9]{8}$/,
}
password: {
//Any character, at least 8
match: /.{8,}/,
//or At least 8 characters in the list
match: /^[0-9A-za-z]{8,}$/,
}
}