Search code examples
regexmeteormeteor-helper

Can RegEx be used with Meteor "check" package?


I am relatively new to Meteor (and really like it -- thank you! framework authors).

My question is about the check package: Is there a way to call check with a RegEx pattern to validate input? I read all of the documentation for the package at the link I provided; the word "pattern" is mentioned several times, but (afaik) it was not meant to refer to a regular expression pattern.

I'm hoping I am missing something, and someone will be able to point me to a way to implement a check() call that uses a regular expression to validate a string.


Solution

  • Yes, you can do it with the Match.Where() pattern.

    Match.Where(function(str){
      check(str, String);
      var regexp = /* your RegExp */;
      return regexp.test(str);
    });
    

    (You are right that the 'patterns' referred to by the check package are not regular expression patterns; they are the 'patterns' listed in the documentation.)