Thread ungültige Datumseingaben (16 answers)
Opened by jan10001 at 2005-03-14 01:51

renee
 2005-03-14 09:05
#52629 #52629
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/perl

use strict;
use warnings;

my %hash = (1 => 31,
2 => 28,
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31,);

for my $datum(qw/12.12.2004 31.02.2006 3.5.1999/){
if($datum =~ /^(([012]?[0-9])|(3[01]))\.((0?[0-9])|(1[0-2]))\.(\d{2}|\d{4})$/){
my ($d,$m,$y) = split /\./, $datum;
$hash{2} = 29 if(is_leap_year($y));
$m =~ s/^0//;
print "yes\n" if($d > 0 && $d < $hash{$m});
}
}

sub is_leap_year{
my ($year) = @_;
return 0 unless($year % 4 == 0);
return 1 if($year % 400 == 0);
return 0 if($year % 100 == 0);
return 1;
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread ungültige Datumseingaben