iban4j icon indicating copy to clipboard operation
iban4j copied to clipboard

Validate Spanish national check digits in IBANs

Open aeinars opened this issue 8 years ago • 5 comments

Currently iban4j doesn't check whether or not the national check digits for Spanish IBANs are calculated correctly. For example, the following two IBANs for the same bank account pass all the checks in iban4j:

ES7021000418450200051322 ES7821000418480200051322

The IBAN checker on https://www.iban.com does not validate the first one, giving the message "Account Number checksum is invalid". The latter passes the test, as "48" is indeed the correct checksum.

Here's a set of tests that in an ideal world should all pass (only the first one does). Are there any plans to add support for verifying that the national check digits are correct?

    public class SpanishIbanTest {
        @Rule
        public ExpectedException expectedException = ExpectedException.none();

        @Test
        public void validSpanishIbanIsValidated() {
            // Validates according to www.iban.com
            IbanUtil.validate("ES7021000418450200051322", IbanFormat.None);
        }

        @Test
        public void invalidSpanishIbanIsNotValidated() {
            // DOES NOT VALIDATE according to www.iban.com
            // The national check digits should be 48, not 45
            expectedException.expectMessage("Exception");
            IbanUtil.validate("ES7821000418480200051322", IbanFormat.None);
        }

        @Test
        public void buildRandomSpanishIban() {
            Iban spanishIban = new Iban.Builder()
                    .countryCode(CountryCode.ES)
                    .bankCode("2100")
                    .branchCode("0418")
                    .accountNumber("0200051322")
                    //.nationalCheckDigit("48")
                    .buildRandom();
            assertThat(spanishIban.getNationalCheckDigit(), is("48"));
        }
    }

aeinars avatar Oct 17 '16 16:10 aeinars

Hello, did you find a solution for this issue? Another library maybe?

fernando-garcia-diaz avatar Jun 01 '23 10:06 fernando-garcia-diaz

AFAIK, iban4j does not validate the national check digits. At least I did not see any code doing this. (but maybe I am wrong)

FrankHossfeld avatar Jun 01 '23 13:06 FrankHossfeld

National bank codes may change over time. Some banks might be added or some might be removed, then maintaining all this information for all supported countries will take a lot of time and effort, and need to release many versions. We can plan for this if there would be more requests

hajk1 avatar Jun 22 '23 10:06 hajk1

Whats supposed solution for now?

ngavrish avatar Jul 05 '23 12:07 ngavrish

@ngavrish National check digits are country specific. Do you know any source we can find them?

hajk1 avatar Jul 10 '23 08:07 hajk1