Validates a user input from prompt
@param string $field
@param string $label
@param string $validator
@param string|null $default
8683
protected function validatePrompt($field, $label, $validator, $default = null)
    {
        $input = $this->prompt($label, $default);

        if (!$this->isValidInput($input, $field, $validator)) {
            $this->errors();
            $this->validatePrompt($field, $label, $validator, $default);
        }
    }
423609
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('ip', 'create')
			->notEmpty('ip');

		$validator
			->requirePresence('session_id', 'create')
			->notEmpty('session_id');

		$validator
			->allowEmpty('result');

		$validator
			->dateTime('used')
			->allowEmpty('used');

		return $validator;
	}
989691
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->allowEmpty('description');

        $validator
            ->integer('status')
            ->requirePresence('status', 'create')
            ->notEmpty('status');

        $validator
            ->integer('priority')
            ->requirePresence('priority', 'create')
            ->notEmpty('priority');

        $validator
            ->date('deadline')
            ->allowEmpty('deadline');

        $validator
            ->decimal('cost')
            ->allowEmpty('cost');

        return $validator;
    }
569831
protected function validateNull($value, ValidationField $field) {
        if ($value === null) {
            return null;
        }
        $field->addError('type', ['messageCode' => 'The value should be null.', 'type' => 'null']);
        return Invalid::value();
    }
288897
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->email('email')
            ->allowEmpty('email');

        $validator
            ->allowEmpty('username');

        $validator
            ->allowEmpty('password');

        $validator
            ->boolean('is_blocked')
            ->allowEmpty('is_blocked');

        return $validator;
    }
1099196
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('subject', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('comment', 'You need to provide a comment subject.'),
                ],
                'length' => [
                    'rule' => ['minLength', 5],
                    'message' => 'Comment subject need to be at least 5 characters long',
                ]
            ])
            ->add('body', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('comment', 'Your comment message cannot be empty')
                ],
                'length' => [
                    'rule' => ['minLength', 5],
                    'message' => 'Comment message need to be at least 5 characters long',
                ]
            ])
            ->allowEmpty('user_id')
            ->allowEmpty('parent_id')
            ->add('parent_id', 'checkParentId', [
                'rule' => function ($value, $context) {
                    if (!empty($value)) {
                        // make sure it's a valid parent: exists and belongs to the
                        // the same bundle (table)
                        $conditions = [
                            'id' => $value,
                            'entity_id' => $context['data']['entity_id'],
                            'table_alias' => $context['data']['table_alias'],
                        ];

                        return TableRegistry::get('Comment.Comments')->find()
                            ->where($conditions)
                            ->count() > 0;
                    } else {
                        $context['data']['parent_id'] = null;
                    }

                    return true;
                },
                'message' => __d('comment', 'Invalid parent comment!.'),
                'provider' => 'table',
            ]);

        return $validator;
    }
132394
public function validate() {

		if ($this->getLabel() === null) {
			throw new ValidationException("'label' can't be null", 'label', $this);
		}
		if ($this->getValue() === null) {
			throw new ValidationException("'value' can't be null", 'value', $this);
		}
	}
125792
public function iSelectRadioButton( $label )
    {
        trigger_error(
            "iSelectRadioButton is deprecated since v6.3.0, use PlatformUI Context iSelectRadioButton instead",
            E_USER_DEPRECATED
        );
        $el = $this->getSession()->getPage()->findField( $label );
        Assertion::assertNotNull( $el, "Couldn't find a radio input with '$label'" );
        $el->check();
    }
1358774
protected function setErrorNumeric($field, $label)
    {
        $error = $this->translation->text('@field must be numeric', array('@field' => $label));
        return $this->setError($field, $error);
    }
1194971
public function validate($field, $input, array $params = array())
    {
        try {
            if ($input == '' || empty($params['0'])) {
                return false;
            }
            $params = $params['0'];
            if (empty($params['rcf_username']) || empty($params['rcf_api'])) {
                return false;
            }
            
            return m62Rcf::getRemoteClient($params, false);
        } catch (\Exception $e) {
            return false;
        }
    }
501162
protected function setErrorExists($field, $label)
    {
        $error = $this->translation->text('@name already exists', array('@name' => $label));
        return $this->setError($field, $error);
    }
27584
public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->allowEmpty('uid', 'create');

        $validator
            ->requirePresence('username', 'create')
            ->notEmpty('username');

        $validator
            ->requirePresence('password', 'create')
            ->notEmpty('password');

        $validator
            ->requirePresence('role', 'create')
            ->notEmpty('role')
            ->add('role', 'inList', [
                'rule' => ['inList', ['admin', 'author']],
                'message' => 'Please enter a valid role'
            ]);

        $validator
            ->boolean('verified')
            ->requirePresence('verified', 'create')
            ->notEmpty('verified');

        $validator
            ->email('email')
            ->requirePresence('email', 'create')
            ->notEmpty('email');

        return $validator;
    }
693987
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create');

        $validator
            ->requirePresence('upload_id', 'create')
            ->notEmpty('upload_id');

        $validator
            ->requirePresence('original_filename', 'create')
            ->notEmpty('original_filename');

        $validator
            ->requirePresence('unique_filename', 'create')
            ->notEmpty('unique_filename');

        $validator
            ->allowEmpty('subfolder');

        $validator
            ->allowEmpty('mimetype');

        $validator
            ->add('size', 'valid', ['rule' => 'numeric'])
            ->requirePresence('size', 'create')
            ->notEmpty('size');

        $validator
            ->requirePresence('hash', 'create')
            ->notEmpty('hash');

        $validator
            ->add('upload_complete', 'valid', ['rule' => 'boolean'])
            ->requirePresence('upload_complete', 'create')
            ->notEmpty('upload_complete');

        $validator
            ->allowEmpty('label');

        $validator
            ->add('created_by', 'valid', ['rule' => 'numeric'])
            ->requirePresence('created_by', 'create')
            ->notEmpty('created_by');

        $validator
            ->add('modified_by', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('modified_by');

        return $validator;
    }
1075109
private function formatField($label, $value)
    {
        if ($value === null) {
            $value = '<comment>None</comment>';
        }

        return [sprintf('<info>%s</info>', $label), $this->formatValue($value)];
    }
461502
public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmpty('email', __d('wasabi_core', 'Please enter an email address.'))
            ->add('email', [
                'email' => [
                    'rule' => 'email',
                    'message' => __d('wasabi_core', 'Please enter a valid email address.')
                ]
            ])
            ->notEmpty('password', __d('wasabi_core', 'Please enter a password.'), 'create')
            ->add('password', [
                'length' => [
                    'rule' => ['minLength', 6],
                    'message' => __d('wasabi_core', 'Ensure your password consists of at least 6 characters.')
                ]
            ])
            ->notEmpty('password_confirmation', __d('wasabi_core', 'Please repeat your Password.'), function ($context) {
                if ($context['newRecord'] === true) {
                    return true;
                }
                if (isset($context['data']['password']) && !empty($context['data']['password'])) {
                    return true;
                }
                return false;
            })
            ->add('password_confirmation', 'equalsPassword', [
                'rule' => function ($passwordConfirmation, $provider) {
                    if ($passwordConfirmation !== $provider['data']['password']) {
                        return __d('wasabi_core', 'The Password Confirmation does not match the Password field.');
                    }
                    return true;
                }
            ])
            ->add('language_id', 'isValid', [
                'rule' => function ($languageId) {
                    $languageIds = Hash::map(Configure::read('languages.backend'), '{n}', function ($language) {
                        return $language->id;
                    });
                    if (!in_array($languageId, $languageIds)) {
                        return __d('wasabi_core', 'Invalid language selected.');
                    }
                    return true;
                }
            ])
            ->add('groups', 'notEmpty', [
                'rule' => function ($groups) {
                    return !empty($groups['_ids'] ?? []);
                },
                'message' => __d('wasabi_core', 'Please select a group this user should belong to.')
            ])
            ->add('groups', 'isValid', [
                'rule' => function ($groups) {
                    if (empty($groups['_ids'])) {
                        return true;
                    }
                    $validGroupIds = $this->Groups->find()->extract('id')->toArray();
                    foreach ($groups['_ids'] as $groupId) {
                        if (!in_array($groupId, $validGroupIds)) {
                            return false;
                        }
                    }
                    return true;
                },
                'message' => __d('wasabi_core', 'Please select a group from the provided list.')
            ]);

        if (Wasabi::setting('Core.User.has_username')) {
            $validator->notEmpty('username', __d('wasabi_core', 'Please enter a username.'));
        }

        if (Wasabi::setting('Core.User.has_firstname_lastname')) {
            $validator->notEmpty('firstname', __d('wasabi_core', 'Please enter a first name.'));
            $validator->notEmpty('lastname', __d('wasabi_core', 'Please enter a last name.'));
        }

        if (Wasabi::setting('Core.User.allow_timezone_change')) {
            $validator->notEmpty('timezone', __d('wasabi_core', 'Please choose a time zone.'));
            $validator->add('timezone', 'isValid', [
                'rule' => function ($timezone) {
                    if (!in_array($timezone, DateTimeZone::listIdentifiers())) {
                        return __d('wasabi_core', 'Invalid timezone selected.');
                    }
                    return true;
                }
            ]);
        }

        return $validator;
    }
303236
public function validate(Validation $validation, $field) : bool
    {
        if (!is_string($field)) {
            throw new Exception(
                "Field name must be a string"
            );
        }



        $label = $this->getOption("label");

        if (empty($label)) {
            $label = $validation->getLabel($field);
        }



        $value = $validation->getValue($field);

        if ($this->isSetOption("allowEmpty") && empty($value)) {
            return true;
        }



        $uuidRegEx = "/^\{?[A-Z0-9]{8}-[A-Z0-9]{4}-[1-5][A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{12}\}?$/i";

        if (!preg_match($uuidRegEx, $value)) {
            $message = $this->getOption("message");

            if (empty($message)) {
                $message = "Field :field must be a valid UUID";
            }



            $replacePairs = [
                ":field" => $label,
            ];

            $validation->appendMessage(
                new Message(
                    strtr($message, $replacePairs),
                    $field,
                    "Uuid"
                )
            );

            return false;
        }



        $allowedVersions = $this->getOption("allowedVersions");

        if (empty($allowedVersions)) {
            $allowedVersions = [1, 2, 3, 4, 5];
        }



        if (!in_array(substr($value, 14, 1), $allowedVersions)) {
            $message = $this->getOption("messageVersion");

            if (empty($message)) {
                $message = "Field :field must be one of the following UUID versions: :versions";
            }



            $replacePairs = [
                ":field" => $label,
                ":versions" => implode(", ", $allowedVersions),
            ];

            $validation->appendMessage(
                new Message(
                    strtr($message, $replacePairs),
                    $field,
                    "Uuid"
                )
            );

            return false;
        }

        return true;
    }
1164615
public function validate($field, $value, $validator) {

		if(empty($value)) return false;
		if(!filter_var($value, FILTER_VALIDATE_URL)) return false;

		$url = parse_url($value);
		if(!in_array($url['scheme'], $this->allowed_protocols)) return false;

		if($this->allowed_domains === null) return true;

		return in_array($url['host'], $this->allowed_domains);

	}