iban4j
iban4j copied to clipboard
Validate Spanish national check digits in IBANs
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"));
}
}
Hello, did you find a solution for this issue? Another library maybe?
AFAIK, iban4j does not validate the national check digits. At least I did not see any code doing this. (but maybe I am wrong)
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
Whats supposed solution for now?
@ngavrish National check digits are country specific. Do you know any source we can find them?