public function validate($data) {
        if(!empty($data)) {
            $lines = explode("\n", $data);
        } else {
            return true;
        }
        $result = true;
        $badips = array();
        foreach ($lines as $line) {
            $tokens = explode('#', $line);
            $ip = trim($tokens[0]);
            if (empty($ip)) {
                continue;
            }
            if (preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
                preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
                preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
            } else {
                $result = false;
                $badips[] = $ip;
            }
        }
        if($result) {
            return true;
        } else {
            return get_string('validateiperror', 'admin', join(', ', $badips));
        }
    }
public function validate($data) {
        if(!empty($data)) {
            $lines = explode("\n", $data);
        } else {
            return true;
        }
        $result = true;
        $badips = array();
        foreach ($lines as $line) {
            $tokens = explode('#', $line);
            $ip = trim($tokens[0]);
            if (empty($ip)) {
                continue;
            }
            if (preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
                preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
                preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
            } else {
                $result = false;
                $badips[] = $ip;
            }
        }
        if($result) {
            return true;
        } else {
            return get_string('validateiperror', 'admin', join(', ', $badips));
        }
    }
public function validate ( $ data ) { if ( ! empty ( $ data ) ) { $ lines = explode ( "\n" , $ data ) ; } else { return true ; } $ result = true ; $ badips = array ( ) ; foreach ( $ lines as $ line ) { $ tokens = explode ( '#' , $ line ) ; $ ip = trim ( $ tokens [ 0 ] ) ; if ( empty ( $ ip ) ) { continue ; } if ( preg_match ( '#^(\d{1,3})(\.\d{1,3}){0,3}$#' , $ ip , $ match ) || preg_match ( '#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#' , $ ip , $ match ) || preg_match ( '#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#' , $ ip , $ match ) ) { } else { $ result = false ; $ badips [ ] = $ ip ; } } if ( $ result ) { return true ; } else { return get_string ( 'validateiperror' , 'admin' , join ( ', ' , $ badips ) ) ; } }
Validate the contents of the textarea as IP addresses

Used to validate a new line separated list of IP addresses collected from
a textarea control

@param string $data A list of IP Addresses separated by new lines
@return mixed bool true for success or string:error on failure
Validate the contents of the textarea as IP addresses