5

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.

tommytwoeyes
  • 483
  • 5
  • 19
  • I think the documentation (http://docs.meteor.com/#/full/matchpatterns) is pretty clear as to what patterns are supported. But since it just throws an exception `Match.Error` you could easily implement your own version that checks a regex. – Christian Fritz Aug 07 '15 at 00:34
  • My question wasn't a criticism of the Meteor documentation. The authors have done an excellent job. But I wasn't asking for subjective opinions about the clarity of the documentation, either. – tommytwoeyes Aug 08 '15 at 00:56
  • too bad you focused on that part of my comment, and not the constructive suggestion. Anyhow, it wasn't meant as criticism of your question. I even up-voted the question. – Christian Fritz Aug 08 '15 at 03:30

1 Answers1

9

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

Jeremy S.
  • 4,599
  • 3
  • 18
  • 25
  • Oh, ok now I see. I overlooked that pattern, which is nice since it lets you implement whatever custom check functionality you need. – tommytwoeyes Aug 07 '15 at 02:56