arturmkrtchyan / iban4j

A Java library for generation and validation of the International Bank Account Numbers (IBAN ISO_13616) and Business Identifier Codes (BIC ISO_9362).
http://iban4j.org
Apache License 2.0
271 stars 124 forks source link

Validate Spanish national check digits in IBANs #34

Open aeinars opened 7 years ago

aeinars commented 7 years ago

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"));
        }
    }
fernando-garcia-diaz commented 1 year ago

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

FrankHossfeld commented 1 year ago

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

hajk1 commented 1 year ago

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

ngavrish commented 1 year ago

Whats supposed solution for now?

hajk1 commented 1 year ago

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