> Now I am continuing on with the same script and I need to check for valid
> IP address form.
> Currently I have:
>
> $ip="255.255.255.0";
>
> if (preg_match ("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", $ip))
{
>      print "Good Ip";
> } else {
>      print "Bad Ip";
> }
>
> This does work kinda.  It checks to see if the 4 sets of  numbers are well
> there and numbers.
> The problem I am having is that it does not check to see if the IP is in a
> proper range ie less than 255.255.255.255
> So you could enter 256.256.256.999 and it will say that it is a good IP.

I think it'd be hard to verify the range with a regex. ip2long and long2ip
do not validate. So, an option would be to write your own little function
that splits the $ip on the period, verifies there are 4 parts, then checks
that each part is between 1 and 255 inclusive.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to