RegEx可以与Meteor“check”包一起使用吗?

时间:2022-04-17 16:21:07

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

我对Meteor相对较新(非常喜欢它 - 谢谢!框架作者)。

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.

我的问题是关于check包:有没有办法用RegEx模式调用check来验证输入?我在我提供的链接上阅读了该软件包的所有文档;多次提到“模式”这个词,但是(afaik)它并不是指正则表达式。

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.

我希望我遗漏了一些东西,并且有人能够指出我实现check()调用的方法,该调用使用正则表达式来验证字符串。

1 个解决方案

#1


9  

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

是的,你可以使用Match.Where()模式。

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

(你是对的,检查包引用的'模式'不是正则表达式模式;它们是文档中列出的'模式'。)

#1


9  

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

是的,你可以使用Match.Where()模式。

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

(你是对的,检查包引用的'模式'不是正则表达式模式;它们是文档中列出的'模式'。)