Package nl.garvelink.iban
Class Modulo97
java.lang.Object
nl.garvelink.iban.Modulo97
Calculates the modulo 97 checksum used in IBAN numbers (and some other entities).
-
Method Summary
Modifier and TypeMethodDescriptionstatic intcalculateCheckDigits(CharSequence input) Calculates the check digits to be used in a MOD97 checked string.static intcalculateCheckDigits(CharSequence countryCode, CharSequence bban) Calculates the check digits for a given country code and BBAN.static intchecksum(CharSequence input) Calculates the raw MOD97 checksum for a given input.static booleanverifyCheckDigits(CharSequence input) Determines whether the given input has a valid MOD97 checksum.
-
Method Details
-
checksum
Calculates the raw MOD97 checksum for a given input.The input is allowed to contain space characters. Any character outside the range
[A-Za-z0-9 ]will cause anIBANParseExceptionto be thrown. This method allocates a temporary buffer of twice the input length, so it will fail for unreasonably large inputs.It is expected, but not enforced, that the characters at index 2 and 3 are numeric. If the existing check digits are
00then this method will return the value that, after subtracting it from 98, gives you the check digits for a MOD-97 verifiable string. If the existing check digits are any other value, this method will return1if the input checksums correctly.You may want to use
calculateCheckDigits(CharSequence)orverifyCheckDigits(CharSequence)instead of this method.- Parameters:
input- the input, which should be at least five characters excluding spaces.- Returns:
- the check digits calculated for the given IBAN.
- Throws:
IBANParseException- if the input is in some way invalid.- See Also:
-
calculateCheckDigits
Calculates the check digits to be used in a MOD97 checked string.- Parameters:
input- the input; the characters at indices 2 and 3 must be'0'. The input must also satisfy the criteria defined inchecksum(CharSequence).- Returns:
- the check digits to be used at indices 2 and 3 to make the input MOD97 verifiable.
- Throws:
IBANParseException- if the input is in some way invalid.
-
calculateCheckDigits
Calculates the check digits for a given country code and BBAN.- Parameters:
countryCode- the country code. Not validated to be a known country.bban- the country-specific BBAN. Not validated to required length.- Returns:
- the check digits to be used at indices 2 and 3 to make the input MOD97 verifiable.
- Throws:
IBANParseException- if either input is null, or the country code is not two characters.- Since:
- 1.9.0
-
verifyCheckDigits
Determines whether the given input has a valid MOD97 checksum.- Parameters:
input- the input to verify, it must meet the criteria defined inchecksum(CharSequence).- Returns:
trueif the input passes checksum verification,falseotherwise.- Throws:
IBANParseException- if the input is in some way invalid.
-