webCOMAND

validate::value()

Validate and return an arbitrary string value against a set of validations.

Prototype

string value(string $value, array $validations, string $invalid_message = NULL)

Parameters

  • value - String to validate.
  • validations - An array of validate strings or object/method pairs.
  • invalid_message - Message to log in validation error if the value does not pass all validations.

Return

Returns the value, even if it does not validate.  Check validate::valid() to determine if the value is valid.

Example

$validate = new \io_comand_web\validate();
$validate->value('email@hostname.com',
    ['trim', 'required', 'email'],
    'Invalid email address'
);
if($validate->valid()) {
    echo('Email is valid.');
}

Related

valid(), validation_errors()