我有一个用户的mongoose模式(UserSchema),我想验证电子邮件是否具有正确的语法.我目前使用的验证如下:
UserSchema.path('email').validate(function (email) {
return email.length
}, 'The e-mail field cannot be empty.')
Run Code Online (Sandbox Code Playgroud)
但是,这仅检查字段是否为空,而不是语法.
是否已经存在我可以重复使用的东西,或者我必须提出自己的方法并在validate函数中调用它?