Can RegEx be used with Meteor "check" package?
Asked Answered
K

1

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.

Kings answered 6/8, 2015 at 23:48 Comment(3)
I think the documentation (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.Quaternary
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.Kings
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.Quaternary
M
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.)

Mattison answered 7/8, 2015 at 1:22 Comment(1)
Oh, ok now I see. I overlooked that pattern, which is nice since it lets you implement whatever custom check functionality you need.Kings

© 2022 - 2024 — McMap. All rights reserved.