Created
September 20, 2022 11:57
-
-
Save deflexor/9c76e7ae67a26d8e6a4d25b253923ad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Validate dates of type DD.MM.YYYY | |
# consider number of days in month and leap years | |
# also year span is from 1900 to 2999 | |
# | |
my $re = qr{ | |
^(?:(?:31\.(?:0?[13578]|1[02]))\.|(?:(?:29|30)\.(?:0?[1,3-9]|1[0-2])\.))(?:(?:19|2\d)?\d{2})$ | |
| | |
^(?:29\.0?2\.(?:(?:(?:19|2\d)?(?:0[48]|[2468][048]|[13579][26]))))$ | |
| | |
^(?:0?[1-9]|1\d|2[0-8])\.(?:(?:0?[1-9])|(?:1[0-2]))\.(?:(?:19|2\d)?\d{2})$ | |
}x; | |
my @dates = qw/ | |
01.12.2000 | |
01.01.2000 | |
31.01.2000 | |
30.11.2999 | |
31.01.1899 | |
31.01.1900 | |
21.01.1900 | |
01.01.3000 | |
20.06 | |
5 | |
xxx | |
/; | |
for (@dates) { | |
print "date: $_"; | |
print /$re/gm ? ' matches!' : ' not match.'; | |
print "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment