hab es jetzt mal so gelöst:
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
35
use constant REGEXP_HOSTNAME => qr/^([\w\-.]+)$/;
use constant REGEXP_IPADDR => qr/^((?:(?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})[.](?:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})))$/;
sub valid_hostname
{
my $value = shift;
return 0 unless $value =~ REGEXP_HOSTNAME;
return 0 unless index($value, ".") > 0;
my @parts = split/\./, $value;
my $valid = @parts;
foreach my $label (@parts)
{
$valid = 0 if (length $label > 63) or ($label =~ m!^\-!) or ($label =~ m!\-$!);
last unless $valid;
}
$valid = 0 if $parts[-1] =~ m!^\d.*!;
return $valid;
}
sub valid_ipaddr
{
my $value = shift;
return $value =~ REGEXP_IPADDR;
}
sub valid_host
{
my $value = shift;
return valid_hostname($value) || valid_ipaddr($value);
}
meinungen erwünscht!\n\n
<!--EDIT|esskar|1091741673-->