尝试在我的应用上设置验证,但我不知道为什么收到此TypeError
这是用于连接到mongodb的Node js应用程序。我已尝试使用Google搜索,但尚未找到答案。
let User = data => {
this.data = data;
this.errors = [];
};
User.prototype.validate = () => {
if (this.data.username == "") {
this.errors.push("You must provide a username.");
}
if (this.data.email == "") {
this.errors.push("You must provide a valid email address");
}
if (this.data.password == "") {
this.errors.push("You must provide a password.");
}
if (this.data.password.length > 0 && this.data.password.length < 12) {
this.errors.push("Username must be at least 12 characters.");
}
if (this.data.password.length > 100) {
this.errors.push("Password cannot exceed 100 characters");
}
if (this.data.username.length > 0 && this.data.username.length < 3) {
this.errors.push("Username must be at least 3 characters.");
}
if (this.data.username.length > 30) {
this.errors.push("Password cannot exceed 30 characters");
}
};
User.prototype.register = () => {
// Step #1: Validate user data
this.validate();
};
module.exports = User;
我希望此输出可以验证注册表单