Tag: validation

在Model.beforeValidate中获取数组值

我正在尝试使用隐藏的input技术来读取checkboxinput的值。 轨/的ActionView /助手/表单助手/ check_box 从ActivityOverlord示例: 视图/用户/ edit.ejs <% if (user.admin) { %> <input type="hidden" name="admin" value="unchecked"> <label class="checkbox"><input type="checkbox" name="admin" checked> Admin</label> <% } else { %> <input type="hidden" name="admin" value="unchecked"> <label class="checkbox"><input type="checkbox" name="admin"> Admin</label> <% } %> API /模型/ user.js的 beforeValidate: function (values, next) { // renamed in Sails v0.10.x // beforeValidation: function […]

玉模板中的节点validation

我对node.js非常陌生,并且在PHP方面有多年的经验,所以我对以下问题的思考可能会受到我支持的方式的影响。 我目前正在使用基础CSS设置节点,并使用它们的揭示模式窗口来显示我的大部分表单。 我想避免在提交时重新显示它们,而是在客户端validation它们。 基本的用户创build将有以下字段: 名称 电子邮件 密码 确认密码 形成我的基本validation我可以使用require来validationinput, input(type="text",name="user[email]",placeholder="@",required) 但是我也希望客户端在用户input之后检查邮件是否已经存在,以及密码是否正确。 我一直在阅读关于validation器模块的内容,但是从我阅读的文档中,我只理解如何在发布后validation值。 我也看到了表单模块,但不再保留,所以我宁愿避免它。 有人能指出我正确的方向吗?

validationMongoose中的子文档

我在Mongoose中使用Schema作为子文档,但是我无法在其字段中对其进行validation。 这就是我所拥有的 var SubdocumentSchema = new Schema({ foo: { type: String, trim: true, required: true }, bar: { type: String, trim: true, required: true } }); var MainDocumentSchema = new Schema({ name: { type: String, trim: true, required: true }, children: { type : [ SubdocumentSchema.schema ], validate: arrayFieldsCannotBeBlankValidation } }); 我想确保子文档的每个字段都不是空的。 我发现这不可能用标准方法来validation数组,所以我写了我的自定义validation函数。 现在我必须手动检查所有的字段是正确的,而不是空的,但它看起来像一个不是真正可扩展的解决scheme,所以我想知道是否有一些本地方法来触发从MainDocument一个子文档validation。

如何从服务器和客户端的angular度来使用3Scale的`authrep`函数?

我正在尝试使用使用3Scale的APIpipe理的nodejs来设置原型API。 我已经能够find他们的插件集成代码,如下所示: var ThreeScale = require('3scale').Client; // keep your provider key secret var client = new ThreeScale("X"); // you will usually obtain app_id and app_key from request params client.authrep({ app_id: "Y", app_key: "Z" }, function(response){ if(response.is_success()) { // continue } else { throw new Error("not authorized " + response.error_message); } }); 这对我来说是服务器模块的一部分。 但是,我不确定客户的凭证在那个等式中。 我看到,因为客户端指向你的应用程序,这里是应用程序的密码…但实际客户端的用户名/密码怎么样!? 在哪里检查? […]

在骨干validation不validation?

嘿所以我知道骨干改变了validation,我正在努力使其工作? 任何人都知道出了什么问题 JSfiddle链接也被validation。 不明白为什么不validation。 http://jsfiddle.net/NcHTb/ 码: (function () { window.App = { Models: {}, Collections: {}, Views: {}, Templates: {}, Router: {} }; App.Models.User = Backbone.Model.extend({ defaults: { firstName: 'first', lastName: 'last', email: 'Email', phone: '222', birthday: 'date' }, validate: function (attrs) { if (!attrs.firstName) { return 'You must enter a real first name.'; } […]

mongoose独特的validation器行为不像其他validation器

在我的用户架构中,我有一个电子邮件字段定义如下: … email: { unique: [true, 'A user with that email address exists. The email must be unique.'], type: String, lowercase: true, required: [true, 'A user must have an email address'] }, … 当我在创build用户时将电子邮件留空时,我可以看到我在模式中定义的cutomised错误消息required: [true, 'A user must have an email address'] 。 但是,如果我select了另一个用户已经使用的电子邮件地址,我得到了一个不同的错误,我看不到在unique字段中定义的自定义邮件unique: [true, 'A user with that email address exists. The email must […]

Node.js – 超出最大调用堆栈大小,即使使用process.nextTick()

我试图写一个“可链式”Express.jsvalidation模块: const validatePost = (req, res, next) => { validator.validate(req.body) .expect('name.first') .present('The parameter is required') .string('The parameter must be a string') .go(next); }; router.post('/', validatePost, (req, res, next) => { return res.send('Validated!'); }); validator.validate的代码(简洁起见): const validate = (data) => { let validation; const expect = (key) => { validation.key = key; // Here I get […]

Hapi / Joivalidation的float()

我有以下JavaScript代码来testingHapi / Joivalidationfunction: var Joi = require('joi'); var schema = { free: Joi.Types.Number().float() }; var value = { free: 3.3333 }; var err = Joi.validate(value, schema); //err is set if value fails to validate against the schema if (err) throw err; validation抛出错误: Error: the value of free must be an integer 我想知道我做错了什么。 我正在使用Hapi和Joi的当前版本。

Expressvalidation器 – 如何允许可选字段

我正在使用express-validator版本2.3.0。 看来,领域始终是必需的 req.check('notexist', 'This failed').isInt(); 将永远失败 – 破碎或我错过了什么? 有一个notEmpty方法的必填字段似乎表明默认是可选的,但我无法获得上述通过。

mongoosevalidation比赛条件?

我有一个叫做Application的模型: var ApplicationSchema = new mongoose.Schema({ name : {type: String, validate: [uniqueName, 'Unique Name']}, dateCreated: Date, containers : [ContainerSchema] }); mongoose.model('Application', ApplicationSchema); var Application = database.model('Application'); 它保存时会调用一个名为uniqueName的validation函数: function uniqueName(name) { console.log('In Unique Name function'); Application.find({}, function(error, documents) { for(var i = 0; i < documents.length; i++) { if(documents[i].name == name) { console.log('About to return false'); […]