Jehanzeb afridi
Jehanzeb afridi

Reputation: 196

Need Regex for MM/yyyy

I need a regular expression for for MM/yyyy. I need to validate only month and year and enforce the user to just enter date like 01/1999 etc...

Upvotes: 1

Views: 223

Answers (3)

Halil Özgür
Halil Özgür

Reputation: 15945

^(0[1-9]|1[0-2])/\d{4}$

Note that this only checks for month. One can enter years like 0000 or 9999. The check for this can be implemented with a few regex constructs, depending on your constraints.

Upvotes: 4

x2.
x2.

Reputation: 9668

\d{2}/\d{4} or \d\d/\d\d\d\d

Upvotes: 0

splash
splash

Reputation: 13327

Try this: \d\d/\d\d\d\d or \d{2}/\d{4} or ^\d{2}/\d{4}$

Upvotes: 2

Related Questions