Change regexp validator for possible use modificators

This commit is contained in:
unknown 2011-05-04 15:01:38 +04:00
parent 8a0d34c288
commit 2fbdf14992
4 changed files with 10 additions and 6 deletions

View file

@ -14,7 +14,7 @@ class Regex extends AbstractRule
public function validate($input)
{
return preg_match("/{$this->regex}/", $input);
return (bool) preg_match($this->regex, $input);
}
}

View file

@ -184,7 +184,7 @@ class NegativeTest extends \PHPUnit_Framework_TestCase
public function testRegex()
{
$this->doTestValidator(v::regex('^[a-f]+$'), 'abcdxxxef');
$this->doTestValidator(v::regex('/^[a-f]+$/'), 'abcdxxxef');
}
public function testString()

View file

@ -7,8 +7,12 @@ class RegexTest extends \PHPUnit_Framework_TestCase
public function testRegexOk()
{
$v = new Regex('w+');
$this->assertTrue($v->assert('wpoiur'));
$v = new Regex('/^[a-z]+$/');
$this->assertTrue($v->validate('wpoiur'));
$this->assertFalse($v->validate('wPoiUur'));
$v = new Regex('/^[a-z]+$/i');
$this->assertTrue($v->validate('wPoiur'));
}
/**
@ -16,7 +20,7 @@ class RegexTest extends \PHPUnit_Framework_TestCase
*/
public function testRegexNot()
{
$v = new Regex('^w+$');
$v = new Regex('/^w+$/');
$this->assertTrue($v->assert('w poiur'));
}

View file

@ -154,7 +154,7 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
public function testRegex()
{
v::regex('^[a-f]+$')->assert('abcdef');
v::regex('/^[a-f]+$/')->assert('abcdef');
}
public function testString()