开发者

Rexeg Combining month name and number exclusively

i'm trying to validate either a month number or month name, using one regular expressi开发者_如何学Con.

I have

/^
0?([1-9]|1[012])                  ---number check 0?1-12
|\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May?|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Sep(?:t)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)$/        ---name check

The two checks work fine separately, im thinking that im not joining the expression correctly, any help appreciated.


Watch where you're putting the alternations:

/^
(?:                 # otherwise the ^ becomes part of the first alternation
 (0?[1-9]|1[012])   # number check 0?1-12
|
 (?:                # name check
  Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|
  Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sept?|September|
  Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?
 )
)
$/
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜