如何在Node.js + Express + Mongoose + Jade中处理表单验证,尤其是嵌套模型 [英] How do you handle form validation, especially with nested models, in Node.js + Express + Mongoose + Jade

查看:75
本文介绍了如何在Node.js + Express + Mongoose + Jade中处理表单验证,尤其是嵌套模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何使用Express和Mongoose处理表单验证?您在使用自定义方法,某些插件还是默认错误数组?

How are you handling form validation with Express and Mongoose? Are you using custom methods, some plugin, or the default errors array?

虽然我可能会看到使用默认错误数组进行一些非常简单的验证,但这种方法似乎在具有嵌套模型的情况下爆炸了.

While I could possibly see using the default errors array for some very simple validation, that approach seems to blow up in the scenario of having nested models.

推荐答案

我个人使用 node-validator 来检查是否来自用户的所有输入字段都是正确的,甚至不会显示给Mongoose.

I personally use node-validator for checking if all the input fields from the user is correct before even presenting it to Mongoose.

Node-validator也非常适合创建所有错误列表,然后可以将这些错误列表呈现给用户.

Node-validator is also nice for creating a list of all errors that then can be presented to the user.

这篇关于如何在Node.js + Express + Mongoose + Jade中处理表单验证,尤其是嵌套模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆