Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16fc595

Browse files
karstennilsennicolas-grekas
authored andcommitted
[Validator] IBAN Check digits should always between 2 and 98
1 parent 84f0b88 commit 16fc595

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)