문제

In my Android app, I'm trying to check if an IBAN bank account number is valid. This supposedly can be done using the Apache IBANCheckDigit. I now try do so as follows:

IBANCheckDigit a = new IBANCheckDigit();
try {
    String checkDigit = a.calculate("MY_IBAN_NUMBER_HERE");
    Boolean b = a.isValid(checkDigit);
    Log.e("isValid: ", b.toString());
} catch (CheckDigitException e) {
    Log.e(this, "THIS IS AN ERROR");
}

This however, always prints false. Even if I insert my own (correct) IBAN-number, it also gives a false.

Does anybody know how to use this Apache IBANCheckDigit? Any tips are welcome!

도움이 되었습니까?

해결책

To check if the IBAN check digits are valid you should use the isValid method only:

Boolean b = a.isValid("MY_IBAN_NUMBER_HERE");
Log.e("isValid: ", b.toString());

The calculate method would compute the check digits if you did not know them already.

다른 팁

iban4j might be good choice for IBAN validation, which is validating not only check digit but also IBAN length, structure, character types, etc...

home page: https://github.com/arturmkrtchyan/iban4j

Code Sample:

try {
    IbanUtil.validate("AT611904300234573201");
    // valid
} catch (IbanFormatException e) {
    // invalid
}

Maven dependency:

<dependency>
     <groupId>org.iban4j</groupId>
     <artifactId>iban4j</artifactId>
     <version>1.0.0</version>
</dependency>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top