for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Fiv\Form\Validator;
/**
* @author Ivan Shcherbak <[email protected]>
*/
class Regexp extends BaseValidator {
* @var string
protected $error = 'Invalid value';
* @var string|null
protected $regexp = null;
* @param string $regexp
* @return $this
* @throws \InvalidArgumentException
public function setRegexp($regexp) {
if (!is_string($regexp)) {
throw new \InvalidArgumentException('Invalid regexp type. Expect string');
}
$this->regexp = $regexp;
return $this;
* @param string $error
public function setError($error) {
$this->error = $error;
* @todo check if we can pass array
*
* @param string $value
* @return bool
public function isValid($value) {
$this->errors = [];
if ($this->regexp === null) {
return true;
if (preg_match($this->regexp, $value)) {
$this->addError($this->error);
return false;