Regular Expression Date Validation

P

Paul Keister

I'm currently using the following regular expression for U.S. date
validation:

\d{1,2}/\d{1,2}/\d{4}| \d{1,2}/\d{1,2}/\d{2}

I could have used

\d{1,2}/\d{1,2}/\d{2,4}

but that would allow the case of a three digit year (I wouldn't sleep at
night!).

My question is this: Why is it that when I use the inverse pattern, e.g.

\d{1,2}/\d{1,2}/\d{2}| \d{1,2}/\d{1,2}/\d{4}

that four digit date strings fail validation? I have a feeling this has
something to do with regex evaluation rules, but I can't quite puzzle it
out.

Just curious,

Paul Keister
PJPM
www.pjpm.biz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top