Friday, 8 November 2019

perl validate get ip address


Method 1:

$ip='25.24.23.21';

print "Valid IP\n" if 4 == grep { /^[^0]+$/ and  $_ <= 255  and  /^\d+$/  } split /\./, $ip;


Method 2:

$ip='25.24.23.21';
$i=0;
for(split /\./, $ip) {
if (/^\d+$/&&/^[^0]+$/&& $_<256)
{
   $i++;
}
}

print "Valid IP" if $i == 3;


Method 3:

$ip='25.24.23.21';

$a=~/^(([0-9]|1*[0-9]{2,2}|2[0-4][0-9]|25[0-5])(\.|$)){4,4}/ ? print "Valid IP" : print "Not Valid IP";

print "Valid IP" if $i == 3;


Method 4:

$ip='25.24.23.21';

$ip=~/^(([01]?\d\d?|2[0-4]\d|25[0-5])[.]?){4}$/ ? print "Valid IP" : print "Not Valid IP";


Method 5:

$ip='25.24.23.21';

$ip=~/^((0|1[0-9]{0,2}|2[0-9]?|2[0-4][0-9]|25[0-5]|[3-9][0-9]?)\.){3}(0|1[0-9]{0,2}|2[0-9]?|2[0-4][0-9]|25[0-5]|[3-9][0-9]?)$/ ? print "Valid IP" : print "Not Valid IP";



0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home