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|\?\?/;
精彩评论