public function testPattern() { $textField = new TextField(array('id' => 'id', 'maxLength' => 10, 'pattern' => '^[a-zA-Z]{5}$', 'patternMessage' => 'Message!'), array()); $textField->fromRequest(array('id' => 'abcde')); $this->assertTrue($textField->validate()); $textField->fromRequest(array('id' => 'abcdef')); $this->assertFalse($textField->validate()); }
public function validate() { if (!parent::validate()) { return false; } if (strlen($this->value) > 0) { if (!$this->validateFormat()) { return false; } if ($this->minValue !== false && $this->value < $this->minValue) { $this->errorMessage = sprintf('Please enter a value of %d or higher', $this->minValue); return false; } if ($this->maxValue !== false && $this->value > $this->maxValue) { $this->errorMessage = sprintf('Please enter a value of %d or lower', $this->maxValue); return false; } } return true; }