0

我在一个项目中使用流星,其中 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
});

我已经通过传递非字符串值或在名称字段中省略强制值来测试架构是否有效。所有这些都按预期工作。

但是,正则表达式验证不起作用。它似乎接受任何字符串,例如 '123%^&'。我在这里测试了许多这些字符串,它们都不应该通过。这是我第一次使用带有简单模式的预定义正则表达式以外的任何东西,并且想知道我是否错过了一些东西。

我也尝试将正则表达式放在一个数组中,效果相同。

我正在使用 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. 
4

1 回答 1

0

我自己解决了这个问题。根据上面的评论,我必须将类型设置为

type: String

代替

type: "String"

然后这触发了正则表达式被触发。

于 2016-02-27T15:09:37.147 回答