开发者

How do I add two questionmarks and a whitespace to my RegEx?

开发者 https://www.devze.com 2023-03-21 03:40 出处:网络
How do I add a whitespace and two questionmarks \'??\' to this RegEx /51|02|52/. I have tried a number of ways but nothing\'s working.

How do I add a whitespace and two questionmarks '??' to this RegEx /51|02|52/. I have tried a number of ways but nothing's working.

Here is the rest of the code, so you can get a clear picture of what I'm attempting to do:

$('.numeric-year').keyup(function () {
    var theseNumbers = /51|02|52/;
    $(this).toggleClass('field-error', !theseNumbers.test(this.value));开发者_开发问答
}); 

I've tried adding \s for the whitespace to the RegEx but it hasnt worked. I've also tried adding |?? for the two questionmarks yet again no success

Would really appreciate some help with this one, Thanks


A ? is a special character, namely the quantifier '0 or 1'. You'd need to escape it.

As for whitespace, use + quantifier, meaning '1 or more'.

/51|02|52|\?\?|\s+/


You'll have to escape those question marks:

var theseNumbers = /51|02|52|\?\?/;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号