* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Constraints; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; /** * @author Michael Hirschler * * @see https://en.wikipedia.org/wiki/ISO_9362#Structure */ class BicValidator extends ConstraintValidator { /** * {@inheritdoc} */ public function validate($value, Constraint $constraint) { if (null === $value || '' === $value) { return; } $canonicalize = str_replace(' ', '', $value); // the bic must be either 8 or 11 characters long if (!in_array(strlen($canonicalize), array(8, 11))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_LENGTH_ERROR) ->addViolation(); return; } // must contain alphanumeric values only if (!ctype_alnum($canonicalize)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_CHARACTERS_ERROR) ->addViolation(); return; } // first 4 letters must be alphabetic (bank code) if (!ctype_alpha(substr($canonicalize, 0, 4))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_BANK_CODE_ERROR) ->addViolation(); return; } // next 2 letters must be alphabetic (country code) if (!ctype_alpha(substr($canonicalize, 4, 2))) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_COUNTRY_CODE_ERROR) ->addViolation(); return; } // should contain uppercase characters only if (strtoupper($canonicalize) !== $canonicalize) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Bic::INVALID_CASE_ERROR) ->addViolation(); return; } } } __halt_compiler();----SIGNATURE:----MUasf+5VGNaKtSe7Y754/xxMV8Xu28qKcMYBH9Lr43RpKXHCfWzD0G2l4lXlKzTRJuThrYi8KHxvJHsAtaiyig1hjJhN/Qs/UH5rtAet23ndZ5kFFtZTYowZO3A7vmp8Qp+j9q81EY5UoezDKAgBPodxf7IUBcmgHdXBQKRU+yepUf0RusPeL6vu60iS+FOD//SiduShQ3z/PEDXDf2bi7HffyQqHeUQ2kNN2ZWc0K4RKNVQ7cpMwxQL58pxS3z475IlvMT8f8A1MRmANst9DiEoLWA/geTML0flqk88WznMcdxPV6EpbgQ6LO46sgvXHLrX9dJ2cHzDM7Dudx71C5g0zhUfpQQaD38LjauRJN7JsBHvXn0EK06LMpihfG5G5XsMxlIomsC1QRIGmNrG72DAInCFG/gFxLdSsQqm+s8q6sab8SHREVxd/TnRaKBXb4wj7DqUwE8N0UaC7rF9KyjcsvMC/edUcfELiQn4qAObRBbZLauz8Z+l4M+y6itfN8b2fJ/8B9u28Gtj8TaTZeCILO+0dJqZ42CK0hbTKDkXeL847J7F/0HIf5ZMHAncVHBPBR3SCUrCyaRWbAsil+GEpIM3uVvWyK6ZqSE7Bsk0WxFSXIhi+ykeThnuD5ROcCpOf9hw6DT+5AzTBwCGsbQrmczDaEhuo6dtiuD/OBQ=----ATTACHMENT:----Mjg1MjQ4NDUyMTg3NzkzNiA4ODk2MjM3OTQ0NTkxOTcgNDcyMzI3MjczODA0MDkxMQ==