Class Modulo97

java.lang.Object
nl.garvelink.iban.Modulo97

public abstract class Modulo97 extends Object
Calculates the modulo 97 checksum used in IBAN numbers (and some other entities).
  • Method Details

    • checksum

      public static int checksum(CharSequence input)
      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 an IBANParseException to 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 00 then 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 return 1 if the input checksums correctly.

      You may want to use calculateCheckDigits(CharSequence) or verifyCheckDigits(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

      public static int calculateCheckDigits(CharSequence input)
      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 in checksum(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

      public static int calculateCheckDigits(CharSequence countryCode, CharSequence bban)
      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

      public static boolean verifyCheckDigits(CharSequence input)
      Determines whether the given input has a valid MOD97 checksum.
      Parameters:
      input - the input to verify, it must meet the criteria defined in checksum(CharSequence).
      Returns:
      true if the input passes checksum verification, false otherwise.
      Throws:
      IBANParseException - if the input is in some way invalid.