mirror of
https://github.com/Respect/Validation.git
synced 2024-06-27 17:50:13 +02:00
Change regexp validator for possible use modificators
This commit is contained in:
parent
8a0d34c288
commit
2fbdf14992
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue