public function check($value) { return jFilter::isIPv4($value); }
/** * check the validity of an IP address * @param string $ip IP of the member * @return boolean */ public static function checkIp($ip) { $validIp = false; $newIp = ''; //0) checking the content : list or range but not list AND range : if (strpos($ip, ',') > 0 and strpos($ip, '-') > 0) { jMessage::add(jLocale::get('havefnubb~ban.list.ip.or.range')); return false; } elseif (strpos($ip, ',') > 0) { $list = preg_split('/,/', $ip); foreach ($list as $item) { $validIp = jFilter::isIPv4($item); if ($validIp === false) { jMessage::add(jLocale::get('havefnubb~ban.invalid.list.of.ip')); return false; } } } elseif (strpos($ip, '-') > 0) { // ip is xxx.yyy.zzz-aaa $list = preg_split('/-/', $ip); // find xxx.yyy. $pos = strrpos($list[0], '.'); // start is xxx.yyy.zzz $start = $list[0]; // end is xxx.yyy.aaa $end = substr($list[0], 0, $pos) . '.' . $list[1]; // validate each of them $validIp1 = jFilter::isIPv4($start); $validIp2 = jFilter::isIPv4($end); if ($validIp1 === false or $validIp2 === false) { jMessage::add(jLocale::get('havefnubb~ban.invalid.range.of.ip', array($start, $end))); return false; } else { return true; } } else { $validIp = jFilter::isIPv4($ip); if ($validIp === false) { jMessage::add(jLocale::get('havefnubb~ban.invalid.ip')); return false; } } return $validIp; }