class IbanValidator

@author Manuel Reinhard <manu@sprain.ch> @author Michael Schummel @link http://www.michael-schummel.de/2007/10/05/iban-prufung-mit-php/

Hierarchy

Expanded class hierarchy of IbanValidator

1 file declares its use of IbanValidator
IbanValidatorTest.php in drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Constraints/IbanValidator.php, line 22

Namespace

Symfony\Component\Validator\Constraints
View source
class IbanValidator extends ConstraintValidator {

  /**
   * {@inheritDoc}
   */
  public function validate($value, Constraint $constraint) {
    if (null === $value || '' === $value) {
      return;
    }
    $teststring = preg_replace('/\\s+/', '', $value);
    if (strlen($teststring) < 4) {
      $this->context
        ->addViolation($constraint->message, array(
        '{{ value }}' => $value,
      ));
      return;
    }
    $teststring = substr($teststring, 4) . strval(ord($teststring[0]) - 55) . strval(ord($teststring[1]) - 55) . substr($teststring, 2, 2);
    $teststring = preg_replace_callback('/[A-Za-z]/', function ($letter) {
      return intval(ord(strtolower($letter[0])) - 87);
    }, $teststring);
    $rest = 0;
    $strlen = strlen($teststring);
    for ($pos = 0; $pos < $strlen; $pos += 7) {
      $part = strval($rest) . substr($teststring, $pos, 7);
      $rest = intval($part) % 97;
    }
    if ($rest != 1) {
      $this->context
        ->addViolation($constraint->message, array(
        '{{ value }}' => $value,
      ));
      return;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConstraintValidator::$context protected property
ConstraintValidator::initialize public function Initializes the constraint validator. Overrides ConstraintValidatorInterface::initialize 1
IbanValidator::validate public function Checks if the passed value is valid. Overrides ConstraintValidatorInterface::validate