Forum Moderators: coopster
I decided the best approach would be to write a different one for each month.
For something like January, I wrote the following, but it dosn't seem to catch an obviously wrong date like "1/32/2008". Might somebody be able to point out what I did wrong?
/^0?1\/(0?[1-9])¦([12][0-9])¦(3[01])\/2008$/
I figured out why my month sample wasn't working, and then spent the last couple of hours making a regex statement that works for what I need.
It's not perfect. It only works for four digit years, and doesn't account for the dates pre-Gregorian (years 1582 and less).
It also dosn't account for the leap year acceptions. For the current millenium it will think that there is a 29th day in February for 2100, 2200, 2300, 2500, 2600, 2700, 2900 and 3000 when there actually isn't. I couldn't figure out how to exclude those leap year exceptions, but since I'll be long dead before the first exception, I didn't care that much. (Sloppy coding I know.)
Anyways, thought those who come across this post might be interested:
/^(((0?[13578]¦1[02])\/31¦(0?[13-9]¦1[012])\/(29¦30)¦(0?[1-9]¦1[012])\/(0?[1-9]¦1[0-9]¦2[0-8]))\/[0-9]{4}¦0?2\/29\/[0-9]{2}([02468][048]¦[13579][26]))$/