Joi验证用户名和邮箱双登录的方案
可以使用Joi的anyOf()方法来实现用户名和邮箱的双登录验证,并且避免报错 'Object schema cannot be a joi schema'。修改后的代码如下:
const usernameEmail = Joi.string().pattern(/^[A-Za-z0-9一-龥-ゟ゠-ヿㇰ-ㇿ가-힣]+$/).min(1).max(50).required();
const login_schema = {
body: {
usernameEmail,
password
}
};
这样就可以同时验证用户名和邮箱的登录了。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qhYi 著作权归作者所有。请勿转载和采集!