Validates country format
@return boolean
194252
protected function validateFormatCountry()
    {
        $field = 'format';
        $format = $this->getSubmitted($field);

        if (!isset($format)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Format');

        if (!is_array($format)) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        $default = $this->country->getDefaultFormat();

        if (!array_intersect_key($format, $default)) {
            $this->setErrorInvalid($field, $label);
            return false;
        }

        foreach ($format as $key => $value) {

            if (!is_array($value) || !array_intersect_key($value, $default[$key])) {
                $this->setErrorInvalid($field, $label);
                return false;
            }

            foreach ($value as $v) {
                if (!in_array(gettype($v), array('string', 'integer', 'boolean'))) {
                    $this->setErrorInvalid($field, $label);
                    return false;
                }
            }
        }

        return true;
    }
1270139
protected function getCountryFormatAddress()
    {
        $updating = $this->getUpdating();

        if (isset($updating['country_format'])) {
            return $updating['country_format'];
        }

        $field = 'country';
        $code = $this->getSubmitted($field);

        if (!isset($code)) {
            return $this->country->getDefaultFormat();
        }

        $country = $this->country->get($code);

        if (empty($country['format'])) {
            $this->setErrorUnavailable($field, $this->translation->text('Country'));
            return array();
        }

        return $country['format'];
    }
71565
public function validate()
    {
        // we don't validate for empty upload fields yet
        if (empty($this->tmpFile['name'])) {
            return true;
        }

        // Check file upload
        if (!$this->isValidUpload()) {
            $this->errors[] = _t('SilverStripe\\Assets\\File.NOVALIDUPLOAD', 'File is not a valid upload');
            return false;
        }

        // Check file isn't empty
        if ($this->isFileEmpty()) {
            $this->errors[] = _t('SilverStripe\\Assets\\File.NOFILESIZE', 'Filesize is zero bytes.');
            return false;
        }

        // filesize validation
        if (!$this->isValidSize()) {
            $arg = File::format_size($this->getAllowedMaxFileSize($this->getFileExtension()));
            $this->errors[] = _t(
                'SilverStripe\\Assets\\File.TOOLARGE',
                'Filesize is too large, maximum {size} allowed',
                'Argument 1: Filesize (e.g. 1MB)',
                array('size' => $arg)
            );
            return false;
        }

        // extension validation
        if (!$this->isValidExtension()) {
            $this->errors[] = _t(
                'SilverStripe\\Assets\\File.INVALIDEXTENSION_SHORT_EXT',
                'Extension \'{extension}\' is not allowed',
                [ 'extension' => $this->getFileExtension() ]
            );
            return false;
        }

        return true;
    }
1079712
protected function validateDataThemeStore()
    {
        $field = 'data.theme';
        $value = $this->getSubmitted($field);
        $module = $this->module->get($value);

        if (isset($module['type']) && $module['type'] === 'theme' && !empty($module['status'])) {
            return true;
        }

        $this->setErrorUnavailable($field, $this->translation->text('Theme'));
        return false;
    }
802303
protected function validateFieldAddress($field)
    {
        if ($this->isExcluded($field) || $this->isError('country')) {
            return null;
        }

        $value = $this->getSubmitted($field);

        if ($this->isUpdating() && !isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $format = $this->getCountryFormatAddress();

        if (empty($format[$field]['required'])) {
            return null;
        }

        if (!isset($value) || $value === '' || mb_strlen($value) > 255) {
            $this->setErrorLengthRange($field, $format[$field]['name'], 1, 255);
            return false;
        }

        return true;
    }
437693
protected function validateCountry()
    {
        $id = $this->getUpdatingId();

        if ($id === false) {
            return null;
        }

        $data = $this->country->get($id);

        if (empty($data)) {
            $this->setErrorUnavailable('update', $this->translation->text('Country'));
            return false;
        }

        $this->setUpdating($data);
        return true;
    }
1143754
public static function validate($phoneNumber, $country = null)
    {
        $phoneNumber = trim($phoneNumber);
        if (empty($phoneNumber)) {
            return false;
        }
        $country = strtoupper($country);
        $phoneUtil = PhoneNumberUtil::getInstance();
        try {
            $numberProto = $phoneUtil->parse($phoneNumber, $country);
        } catch (NumberParseException $e) {
            return false;
        }

        return $phoneUtil->isValidNumber($numberProto);
    }
896214
protected function isValidFormat()
    {
        //    Reading 2048 bytes should be enough to validate that the format is HTML
        $data = fread($this->fileHandle, 2048);
        if ((strpos($data, '<') !== false) &&
                (strlen($data) !== strlen(strip_tags($data)))) {
            return true;
        }

        return false;
    }
32303
protected function validateStateAddress()
    {
        $field = 'state_id';
        $value = $this->getSubmitted($field);

        if (!isset($value)) {
            $this->unsetSubmitted($field);
            return null;
        }

        $label = $this->translation->text('Country state');
        $format = $this->getCountryFormatAddress();

        if (empty($value) && !empty($format['state_id']['required'])) {
            $this->setErrorRequired($field, $label);
            return false;
        }

        if (!is_numeric($value)) {
            $this->setErrorNumeric($field, $label);
            return false;
        }

        if (empty($value)) {
            return true;
        }

        $state = $this->state->get($value);

        if (empty($state)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        return true;
    }
796169
public function validateVatNumberFormat(string $vatNumber) : bool
    {
        if ($vatNumber === '') {
            return false;
        }

        $vatNumber = strtoupper($vatNumber);
        $country = substr($vatNumber, 0, 2);
        $number = substr($vatNumber, 2);

        if (! isset($this->patterns[$country]) ) {
            return false;
        }

        $matches = preg_match('/^' . $this->patterns[$country] . '$/', $number) > 0;
        return $matches;
    }
1099820
public function format()
    {
        return sprintf(
            '%s %s %s',
            $this->getCountryCode() . $this->getChecksum(),
            substr($this->getInstituteIdentification(), 0, 4),
            implode(' ', str_split($this->getBankAccountNumber(), 4))
        );
    }
1046505
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;
    }
1177312
public function validate($locale)
    {
        if (!$locale) {
            return false;
        }
        $lang = $this->langFromLocale($locale);
        $region = $this->countryFromLocale($locale);
        if (!$lang || !$region) {
            return false;
        }

        // Check the configurable whitelist
        $localeCode = strtolower($lang) . '_' . strtoupper($region);
        $locales = $this->getLocales();

        if (array_key_exists($localeCode, $locales)
            || array_key_exists(strtolower($localeCode), $locales)
        ) {
            return true;
        }

        // Fallback
        return strcasecmp($lang, $region)
            && strcasecmp($lang, $locale)
            && strcasecmp($region, $locale);
    }
162782
public function isValid()
    {
        // these schemes are allowed
        $allowedSchemes = $this->getAllowedSchemes();

        // get the field value
        $url = $this->field->getValue();


        // not required and empty? Then its valid
        if ($this->isNotRequiredAndEmpty($url)) {
            return true;
        }

        if ($this->getMaxLength() && strlen($url) > $this->getMaxLength()) {
            // Over maximum length.
            return false;
        }

        // do simple validation
        if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED | FILTER_FLAG_SCHEME_REQUIRED)) {
            return false;
        }

        // check if we have a tld
        if (!$this->isSkipTldCheck() && !preg_match('#\.[a-z]{2,}$#', parse_url($url, PHP_URL_HOST))) {
            return false;
        }

        // further validation is required.
        if (in_array(parse_url($url, PHP_URL_SCHEME), $allowedSchemes)) {
            return true;
        }

        return false;
    }
1100171
public function validate(){
        if(count($this->fieldsState) == 0){
            //Si no hay datos devuelve TRUE
            return TRUE;
        }
        else{
            //Si hay datos valida sus reglas            
            //El formulario empieza siendo valido
            $form_valid= TRUE;            
            //Recorro todos los datos y sus reglas
            foreach ($this->fieldsState as $fieldState) {
                $valid= TRUE;                
                //Recorro cada regla del dato
                foreach ($fieldState['rules'] as $rule) {
                    //Ve el tipo de regla, con o sin parametros
                    if (count(explode('[', $rule)) > 1){
                        //Si hay reglas con parametros, separa la regla y su parametro               
                        $vars= explode('[', $rule);
                        $rule= $vars[0];
                        $var= explode(']', $vars[1]);
                        $var= $var[0];
                        //Realiza el llamado a la funcion correspondiente
                        $valid= call_user_func_array(array($this, $rule), array($fieldState['name'], $fieldState['value'], $var));
                    }
                    else{
                        //Regla sin parametros
                        //Realiza el llamado a la funcion correspondiente
                        $valid= call_user_func_array(array($this, $rule), array($fieldState['name'], $fieldState['value']));
                    }
                    
                    //Si una regla ya no es valida, no reviso las demas
                    if(!$valid){
                        //Asigno al campo Valido del dato FALSE
                        $name= $fieldState['name'];
                        $this->fieldsState["$name"]['valid']= FALSE;
                        break;
                    }
                }                
                //Actualizo el valor de formulario_valido de manera que si ya es falso se mantiene en falso
                $form_valid= $form_valid && $valid;
            }            
            return $form_valid;
        }
    }
928844
protected function validateForm()
    {
        if (2 == $this->currentStep) {
            return true;
        }
        // Note we use an MUtil_Form
        return $this->_form->isValid($this->formData, $this->disableValidatorTranslation);
    }
96512
private function validateRegex(): bool
    {
        $isValid = \preg_match($this->options['pattern'], $this->value) ? true : false;
        if (!$isValid) {
            $this->setError(self::VALIDATOR_ERROR_REGEX_PATTERN_NOT_MATCH);
        }
        return $isValid;
    }