How to check the date validity?

Andreas Perstinger andipersti at
Tue Dec 24 07:19:10 CET 2013

Jason Friedman <jsf80238 at> wrote:
>Would this not work?
>import re
>if"\d{1,2}:\d{2}:\d{2}(.\d{1,3})?", "12:55:55.705"):
>    # It's a time

No, because this regexp also matches stuff like "99:99:99.999".
Checking for the number of digits is not enough, because not all
combinations of two digits are valid hours, minutes or seconds.

Bye, Andreas

More information about the Python-list mailing list