|
@@ -15,6 +15,12 @@ use Symfony\Component\Validator\Constraint;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\ConstraintValidator;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Validates whether a value match or not given regexp pattern
|
|
|
|
+ *
|
|
|
|
+ * @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
|
|
|
+ * @author Joseph Bielawski <stloyd@gmail.com>
|
|
|
|
+ */
|
|
class RegexValidator extends ConstraintValidator
|
|
class RegexValidator extends ConstraintValidator
|
|
{
|
|
{
|
|
public function isValid($value, Constraint $constraint)
|
|
public function isValid($value, Constraint $constraint)
|
|
@@ -29,11 +35,7 @@ class RegexValidator extends ConstraintValidator
|
|
|
|
|
|
$value = (string) $value;
|
|
$value = (string) $value;
|
|
|
|
|
|
- if (
|
|
|
|
- ($constraint->match && !preg_match($constraint->pattern, $value))
|
|
|
|
- ||
|
|
|
|
- (!$constraint->match && preg_match($constraint->pattern, $value))
|
|
|
|
- ) {
|
|
|
|
|
|
+ if ($constraint->match XOR preg_match($constraint->pattern, $value)) {
|
|
$this->setMessage($constraint->message, array('{{ value }}' => $value));
|
|
$this->setMessage($constraint->message, array('{{ value }}' => $value));
|
|
|
|
|
|
return false;
|
|
return false;
|