Skip to content

[Validator] IBAN Check digits should always between 2 and 98 #54924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Symfony/Component/Validator/Constraints/IbanValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ public function validate($value, Constraint $constraint)
return;
}

// Check digits should always between 2 and 98
// A ECBS document (https://www.ecbs.org/Download/EBS204_V3.PDF) replicates part of the ISO/IEC 7064:2003 standard as a method for generating check digits in the range 02 to 98.
$checkDigits = (int) substr($canonicalized, 2, 2);
if ($checkDigits < 2 || $checkDigits > 98) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Iban::CHECKSUM_FAILED_ERROR)
->addViolation();

return;
}

// Move the first four characters to the end
// e.g. CH93 0076 2011 6238 5295 7
// -> 0076 2011 6238 5295 7 CH93
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ public static function getIbansWithValidFormatButIncorrectChecksum()
['UA213223130000026007233566002'], // Ukraine
['AE260211000000230064017'], // United Arab Emirates
['VA59001123000012345671'], // Vatican City State

// Checksum digits not between 02 and 98
['FO00 5432 0388 8999 44'], // Faroe Islands
['NL01INGB0001393698'], // Netherlands
['NL01RABO0331811235'], // Netherlands
['RU99 0445 2560 0407 0281 0412 3456 7890 1'], // Russia
];
}

Expand Down
Loading