How to check the date validity?

Andreas Perstinger andipersti at gmail.com
Tue Dec 24 01:19:10 EST 2013


Jason Friedman <jsf80238 at gmail.com> wrote:
>Would this not work?
>import re
>if re.search(r"\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