Skip to content

Commit 02f6cbc

Browse files
committed
Fixing the year ranges
1 parent 28061d2 commit 02f6cbc

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

codonPython/dateValidator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ def validDate(date_string: str)->bool:
2727
"""
2828

2929
# This regex string will validate dates of type `dd/mm/yyyy`, `dd-mm-yyyy` or `dd.mm.yyyy`
30-
# from years 1900 - 9999. Leap year support included. Regex string from
30+
# from years 1900 - 2049. Leap year support included. Original Regex string based on
3131
# https://stackoverflow.com/questions/15491894/regex-to-validate-date-format-dd-mm-yyyy
32-
if re.match(r"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:19|[2-9]\d)?\d{2})$", date_string, flags=0):
32+
# modified to confine the year dates.
33+
if re.match(
34+
r"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1" +
35+
r"|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2" +
36+
r"))(?:(?:1[9]..|2[0][0-4].))$|^(?:29(\/|-|\.)0?2\3" +
37+
r"(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]" +
38+
r"|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4" +
39+
r"(?:(?:1[9]..|2[0][0-4].))$",
40+
date_string, flags=0):
3341
return True
3442
else:
35-
return False
43+
return False

0 commit comments

Comments
 (0)