johnnywang has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Test::More 'no_plan'; my @good=("www.foo.com","www.411.com","123.34.3.5","web.foo.info", "www.foo.co.uk","aaaa-4-bbbb.cCc.COM"); my @bad = ("foo.23.4.2","foo","23","234.12.4.5.4","2345.23.4.43"); ok(is_valid($_)) foreach @good; ok(!is_valid($_)) foreach @bad; sub is_valid{ my $name = shift; my $name = lc $name; return ($name && $name =~ /^[-\.\w]+\.\w+$/ #at least two levels && ($name !~ /\.\d+$/ || $name =~ /^\d{1,3}\.\d{1,3}\.\d{1 +,3}\.\d{1,3}$/) #if last part is digit, better be ip ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Syntactically check domain name/IP
by tachyon (Chancellor) on Oct 01, 2004 at 01:00 UTC | |
by Smylers (Pilgrim) on Oct 01, 2004 at 10:12 UTC | |
by tachyon (Chancellor) on Oct 02, 2004 at 08:29 UTC | |
|
Re: Syntactically check domain name/IP
by zeimusu (Sexton) on Oct 01, 2004 at 00:09 UTC | |
|
Re: Syntactically check domain name/IP
by NetWallah (Canon) on Oct 01, 2004 at 00:03 UTC | |
|
Re: Syntactically check domain name/IP
by Anonymous Monk on Oct 01, 2004 at 10:09 UTC | |
|
Re: Syntactically check domain name/IP
by Beechbone (Friar) on Oct 01, 2004 at 14:53 UTC |