Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1814149

Browse filesBrowse files
committed
IBAN 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. 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.
1 parent 84f0b88 commit 1814149
Copy full SHA for 1814149

File tree

2 files changed

+18
-3
lines changed
Filter options

2 files changed

+18
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/IbanValidator.php
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ class IbanValidator extends ConstraintValidator
163163
'YT' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // France
164164
];
165165

166-
/**
167-
* {@inheritdoc}
168-
*/
169166
public function validate($value, Constraint $constraint)
170167
{
171168
if (!$constraint instanceof Iban) {
@@ -228,6 +225,18 @@ public function validate($value, Constraint $constraint)
228225
return;
229226
}
230227

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php
+6Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.