8000 bug #54924 [Validator] IBAN Check digits should always between 2 and … · symfony/symfony@a8a31e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8a31e6

Browse files
bug #54924 [Validator] IBAN Check digits should always between 2 and 98 (karstennilsen)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Validator] IBAN Check digits should always between 2 and 98 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes/no | New feature? | no | Deprecations? | no | Issues | No existing | License | MIT 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. Besides this I have a production database of 160K valid IBANs. All of them have a check digit between 02 and 98. Example of invalid IBANs, which before were valid, are NL01INGB0001393698 and NL01RABO0331811235. You can check them at iban.com to verify they are indeed invalid. Commits ------- 16fc595 [Validator] IBAN Check digits should always between 2 and 98
2 parents 03465f2 + 16fc595 commit a8a31e6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Symfony/Component/Validator/Constraints/IbanValidator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ public function validate($value, Constraint $constraint)
228228
return;
229229
}
230230

231+
// Check digits should always between 2 and 98
232+
// 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.
233+
$checkDigits = (int) substr($canonicalized, 2, 2);
234+
if ($checkDigits < 2 || $checkDigits > 98) {
235+
$this->context->buildViolation($constraint->message)
236+
->setParameter('{{ value }}', $this->formatValue($value))
237+
->setCode(Iban::CHECKSUM_FAILED_ERROR)
238+
->addViolation();
239+
240+
return;
241+
}
242+
231243
// Move the first four characters to the end
232244
// e.g. CH93 0076 2011 6238 5295 7
233245
// -> 0076 2011 6238 5295 7 CH93

src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ public static function getIbansWithValidFormatButIncorrectChecksum()
401401
['UA213223130000026007233566002'], // Ukraine
402402
['AE260211000000230064017'], // United Arab Emirates
403403
['VA59001123000012345671'], // Vatican City State
404+
405+
// Checksum digits not between 02 and 98
406+
['FO00 5432 0388 8999 44'], // Faroe Islands
407+
['NL01INGB0001393698'], // Netherlands
408+
['NL01RABO0331811235'], // Netherlands
409+
['RU99 0445 2560 0407 0281 0412 3456 7890 1'], // Russia
404410
];
405411
}
406412

0 commit comments

Comments
 (0)
0