|
|
Question : Perl - reg exp to check for valid IP format
|
|
hi,
I need to check a string to see if it is a valid IP format i.e. xxx.xxx.xxx.xxx
Can anybody share with me the regular exp. to do this in Perl?
Thanks!
|
Answer : Perl - reg exp to check for valid IP format
|
|
hmm, I didn't know zeros were okay (cause I thought then you'd have to have an ip address 0.0.0.0)
anyhow,
I think it actually made it simpler.
$ip='204.1.19.30'; $ip=~/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/; if($1<256 && $2<256 && $3<256 && $4<256 && ($1+$2+$3+$4)>0) { print "ok" } else {print "nope";}
|
|
|
|
|