Skip to content

Instantly share code, notes, and snippets.

@deflexor
Created September 20, 2022 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deflexor/9c76e7ae67a26d8e6a4d25b253923ad7 to your computer and use it in GitHub Desktop.
Save deflexor/9c76e7ae67a26d8e6a4d25b253923ad7 to your computer and use it in GitHub Desktop.
#
# 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