Does anyone have an egrep regular expression (regex) for valid dates in the format YYYYMMDD?

It's fairly simple for basic checking, for example the DD bit could be:
[0-3][0-9] but that doesn't catch invalid days like 38.

if I write a full regex, starting with ^ and ending in $, I can then use the | (the OR option) along with a second full regex to capture the two cases of [0-2][0-9] and [3][0-1], however that is quite long. (ie. ^<full regex>$|^<second full regex>$)

Ideally I'd like to be able to do an embedded OR within a single regex to capture that 29 is a valid day by 39 is not.  But I can't figure out how to do that.

Of course, something that captured leap years and fancy stuff like that would be awesome, but I'm not holding my breath on it. :)

Thank You,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

egrep '^(19|20)[0-9][0-9](0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])$'

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mj62mj62Author Commented:
Impressive :)

Thanks a million,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.