提交错误与Joi的前端
我有一个注册表格,我正在用Joi验证此表格。 到目前为止,没有问题,我可以反映出JSON的错误,但是我不知道如何在前端打印它,我该怎么做?
我之前使用过Express-validator,那里有一个验证质量结构,因此我可以捕获错误并将其发送到前端。我该如何在这里做到这一点? 你能帮助我吗。
简而言之
const createUserValidation = Joi.object({
name: Joi.string().required().min(5),
username : Joi.string().required().min(3),
password : Joi.string().required().min(8).pattern(new RegExp('^[a-zA-Z0-9]{3,30}$')),
email: Joi.string().required().email(),
});
,我想将错误从这里返回到前端。
从现在开始谢谢你。
I have a registration form and I am validating this form with joi.
There is no problem so far, I can reflect the errors as json, but I don't know how to print it in the frontend, how can I do that?
I used express-validator before, there was a validationresult structure there, so I could catch errors and send them to the front end. How can I do this here?
can you help me.
Validate process like this
const createUserValidation = Joi.object({
name: Joi.string().required().min(5),
username : Joi.string().required().min(3),
password : Joi.string().required().min(8).pattern(new RegExp('^[a-zA-Z0-9]{3,30}
In short, I want to transfer the errors returned from here to the front end.
Thank you from now.
)),
email: Joi.string().required().email(),
});
In short, I want to transfer the errors returned from here to the front end.
Thank you from now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,您必须创建一个尝试捕获,并发送JSON错误:
现在,您可以为新错误更改“消息”:
这样,您可以将消息发送到前面,只需读取它即可。 。
Now you have to create a Try and catch, and send a JSON error:
Now, you can change the "message" for your new error:
With that, you can send the message to the front, and there just have to read it... For that, if u use Redux, can
And with that, you can get the error to your front =)
R³