Regular expression to match credit card expiration date

Viewed 33447

I have the following pattern which I'm trying to use to match credit card expiration dates:

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

and I'm testing on the following strings:

02/13
0213
022013
02/2013
02/203
02/2
02/20322

It should only match the first four strings, and the last 3 should not be a match as they are invalid. However the current pattern is also matching the last string. What am I doing wrong?

3 Answers
Related