Meteor / aldeed:simple-schema - RegexProblem

188 Views Asked by At

I'm using meteor on a project where aldeed:simple-schema is used to validate inputs. My schema looks like this:

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
});

I have tested that the schema works by passing non-String values or leaving out a mandatory value in the name fields. All of these worked as expected.

However the regEx validation is not working. It seems to accept any string such as '123%^&'. I've tested a number of these strings here and they should all not pass. It's the first time I've used anything other than the predefined regexes with simple schema and wonder if I missed something.

I have also tried to place the regular expression in an array, with the same effect.

I am using Meteor 1.2 and have updated to the latest version of all packages:

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. 
1

There are 1 best solutions below

0
On

I solved the problem myself. As per comment above I had to set the type as

type: String

instead of

type: "String"

This then triggered the regular expression to be fired.