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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top