public function validate($data) {
        if (empty($data)) {
            return true;
        }
        $ports = explode("\n", $data);
        $badentries = [];
        foreach ($ports as $port) {
            $port = trim($port);
            if (empty($port)) {
                return get_string('validateemptylineerror', 'admin');
            }

            // Is the string a valid integer number?
            if (strval(intval($port)) !== $port || intval($port) <= 0) {
                $badentries[] = $port;
            }
        }
        if ($badentries) {
            return get_string('validateerrorlist', 'admin', $badentries);
        }
        return true;
    }
public function validate($data) {
        if (empty($data)) {
            return true;
        }
        $ports = explode("\n", $data);
        $badentries = [];
        foreach ($ports as $port) {
            $port = trim($port);
            if (empty($port)) {
                return get_string('validateemptylineerror', 'admin');
            }

            // Is the string a valid integer number?
            if (strval(intval($port)) !== $port || intval($port) <= 0) {
                $badentries[] = $port;
            }
        }
        if ($badentries) {
            return get_string('validateerrorlist', 'admin', $badentries);
        }
        return true;
    }
public function validate ( $ data ) { if ( empty ( $ data ) ) { return true ; } $ ports = explode ( "\n" , $ data ) ; $ badentries = [ ] ; foreach ( $ ports as $ port ) { $ port = trim ( $ port ) ; if ( empty ( $ port ) ) { return get_string ( 'validateemptylineerror' , 'admin' ) ; } // Is the string a valid integer number? if ( strval ( intval ( $ port ) ) !== $ port || intval ( $ port ) <= 0 ) { $ badentries [ ] = $ port ; } } if ( $ badentries ) { return get_string ( 'validateerrorlist' , 'admin' , $ badentries ) ; } return true ; }
Validate the contents of the textarea as port numbers.
Used to validate a new line separated list of ports collected from a textarea control.

@param string $data A list of ports separated by new lines
@return mixed bool true for success or string:error on failure
Validate the contents of the textarea as port numbers . Used to validate a new line separated list of ports collected from a textarea control .