. */ /* */ /*************************************************************************************/ namespace WireTransfer\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Thelia\Core\Translation\Translator; /** * Class BICValidator * @package WireTransfer\Constraints * @author Thelia */ class BICValidator extends ConstraintValidator { /** * Checks if the passed value is valid. * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } $teststring = preg_replace('/\s+/', '', $value); if(!preg_match("([a-zA-Z]{4}[a-zA-Z]{2}[a-zA-Z0-9]{2}([a-zA-Z0-9]{3})?)", $teststring)) { $this->context->addViolation( Translator::getInstance()->trans( $constraint->message ), array( '{{ value }}' => $value ) ); } } }