我在一个项目中使用meteor,其中aldeed:simple-schema用于验证输入。我的模式如下所示:
const name = {
type: 'String',
regEx: /^[\w\d]+$/,
optional: false
};
const nationalId = {
type: 'String',
regEx: /^[\w\d]+$/,
optional: true
};
schema = new SimpleSchema({
firstName: name,
lastName: name,
nationalId
});我已经通过传递非字符串值或在name字段中省略必填值来测试该模式的工作方式。所有这些都像预期的那样工作。
但是,regEx验证不起作用。它似乎接受任何字符串,如'123%^&‘。我已经测试了许多这样的字符串here,它们都不应该通过。这是我第一次使用具有简单模式的预定义正则表达式之外的任何东西,我想知道我是否遗漏了什么。
我还尝试将正则表达式放在一个数组中,效果相同。
我使用的是Meteor 1.2,并且已经更新到所有包的最新版本:
accounts-password 1.1.4 Password support for accounts
accounts-ui 1.1.6 Simple templates to add login widgets to an app
aldeed:collection2 2.9.0 Automatic validation of insert and update operations on the client and server.
aldeed:simple-schema 1.5.3 A simple schema validation object with reactivity. Used by collection2 and au...
blaze-html-templates 1.0.1 Compile HTML templates into reactive UI with Meteor Blaze
ecmascript 0.1.6* Compiler plugin that supports ES2015+ in all .js files
es5-shim 4.1.14 Shims and polyfills to improve ECMAScript 5 support
fourseven:scss 3.4.1 Style with attitude. Sass and SCSS support for Meteor.js (with autoprefixer a...
jquery 1.11.4 Manipulate the DOM using CSS selectors
kadira:blaze-layout 2.3.0 Layout Manager for Blaze (works well with FlowRouter)
kadira:flow-router 2.10.1 Carefully Designed Client Side Router for Meteor
mdg:validated-method 1.0.1 A simple wrapper for Meteor.methods
meteor-base 1.0.1 Packages that every Meteor app needs
meteortoys:allthings 2.3.1 Insanely Handy Development Tools
mobile-experience 1.0.1 Packages for a great mobile user experience
mongo 1.1.3 Adaptor for using MongoDB and Minimongo over DDP
session 1.1.1 Session variable
standard-minifiers 1.0.2 Standard minifiers used with Meteor apps by default.
tracker 1.0.9 Dependency tracker to allow reactive callbacks
useraccounts:core 1.13.1 Meteor sign up and sign in templates core package.
wolves:bitters 3.1.0 Meteor 1.2.0+ - Scaffold styles, variables and structure for Bourbon projects.
wolves:bourbon 3.1.0 Meteor 1.2.0+ - Bourbon is a simple and lightweight mixin library for Sass.
wolves:neat 3.1.0 Meteor 1.2.0+ - A lightweight, semantic grid framework built on top of Bourbon. 发布于 2016-02-27 23:09:37
我自己解决了这个问题。根据上面的评论,我必须将类型设置为
type: String而不是
type: "String"这随后触发了触发正则表达式。
https://stackoverflow.com/questions/35671080
复制相似问题