You are here

function services_ipauth_is_valid_ip_range in Services IP Authentication 7

Same name and namespace in other branches
  1. 6 services_ipauth.module \services_ipauth_is_valid_ip_range()

Check if the given IP address is a valid range.

Parameters

string $range The IP range to validate:

Return value

boolean TRUE if it's a valid IP range, FALSE otherwise.

1 call to services_ipauth_is_valid_ip_range()
_services_ipauth_ips_validate in ./services_ipauth.inc
#element_validate callback to validate IP addresses (one per line).

File

./services_ipauth.module, line 35
Hook implementations and general API function for the IP Authentication module.

Code

function services_ipauth_is_valid_ip_range($range) {

  // Replace all non-numeric but legal IP range chars with '|'.
  $range = strtr($range, ' ,.-*', '|||||');
  foreach (explode('|', $range) as $quad) {

    // Return false if quad is not numeric, or if it is numeric and larger than
    // 255 or smaller than 0.
    if (!empty($quad) && !is_numeric($quad) || !empty($quad) && is_numeric($quad) && ($quad > 255 || $quad < 0)) {
      return FALSE;
    }
  }
  return TRUE;
}