Pop\Validator\AlphaNumeric::evaluate PHP Method

evaluate() public method

Method to evaluate the validator
public evaluate ( mixed $input = null ) : boolean
$input mixed
return boolean
    public function evaluate($input = null)
    {
        // Set the input, if passed
        if (null !== $input) {
            $this->input = $input;
        }
        // Set the default message
        if (null === $this->defaultMessage) {
            if ($this->condition) {
                $this->defaultMessage = I18n::factory()->__('The value must only contain alphanumeric characters.');
            } else {
                $this->defaultMessage = I18n::factory()->__('The value must contain non-alphanumeric characters.');
            }
        }
        // Evaluate the input against the validator
        if (preg_match('/^\\w+$/', $this->input) == $this->condition) {
            $this->result = true;
        } else {
            $this->result = false;
        }
        return $this->result;
    }

Usage Example

Ejemplo n.º 1
0
 public function testEvaluateMessageFalse()
 {
     $v = new AlphaNumeric(null, 'This is alphanumeric', false);
     $this->assertEquals('This is alphanumeric', $v->getMessage());
     $this->assertFalse($v->evaluate('abcdef123'));
     $this->assertTrue($v->evaluate('123456$#@'));
 }
All Usage Examples Of Pop\Validator\AlphaNumeric::evaluate
AlphaNumeric