src/Validator/Specific/Alnum.php
private function validateAlnum(): bool
    {
        $charClass = '[:alnum:]';
        if ($this->options['allow-spaces'] === true) {
            $charClass .= '[:space:]';
        }
        if ($this->options['allow-whitespaces'] === true) {
            $charClass .= '[:blank:]';
        }
        $modifier = '';
        if ($this->options['utf-8'] === true) {
            $modifier = 'u';
        }

        $isValid = \preg_match('/^['.$charClass.']+$/'.$modifier, $this->value) ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_ALNUM_NOT_VALID);

            if ($this->options['allow-whitespaces'] === true && $this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-whitespaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID);
            }
        }
        return $isValid;
    }
private function validateAlnum(): bool
    {
        $charClass = '[:alnum:]';
        if ($this->options['allow-spaces'] === true) {
            $charClass .= '[:space:]';
        }
        if ($this->options['allow-whitespaces'] === true) {
            $charClass .= '[:blank:]';
        }
        $modifier = '';
        if ($this->options['utf-8'] === true) {
            $modifier = 'u';
        }

        $isValid = \preg_match('/^['.$charClass.']+$/'.$modifier, $this->value) ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_ALNUM_NOT_VALID);

            if ($this->options['allow-whitespaces'] === true && $this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-whitespaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID);
            } elseif ($this->options['allow-spaces'] === true) {
                $this->setError(self::VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID);
            }
        }
        return $isValid;
    }
private function validateAlnum ( ) : bool { $ charClass = '[:alnum:]' ; if ( $ this -> options [ 'allow-spaces' ] === true ) { $ charClass .= '[:space:]' ; } if ( $ this -> options [ 'allow-whitespaces' ] === true ) { $ charClass .= '[:blank:]' ; } $ modifier = '' ; if ( $ this -> options [ 'utf-8' ] === true ) { $ modifier = 'u' ; } $ isValid = \ preg_match ( '/^[' . $ charClass . ']+$/' . $ modifier , $ this -> value ) ? true : false ; if ( ! $ isValid ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_NOT_VALID ) ; if ( $ this -> options [ 'allow-whitespaces' ] === true && $ this -> options [ 'allow-spaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID ) ; } elseif ( $ this -> options [ 'allow-whitespaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID ) ; } elseif ( $ this -> options [ 'allow-spaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID ) ; } } return $ isValid ; }
Checks whether string is valid alnum string

@return bool
Checks whether string is valid alnum string