Class IBANCheckDigit
- java.lang.Object
-
- org.apache.commons.validator.routines.checkdigit.IBANCheckDigit
-
- All Implemented Interfaces:
java.io.Serializable,CheckDigit
public final class IBANCheckDigit extends java.lang.Object implements CheckDigit, java.io.Serializable
IBAN (International Bank Account Number) Check Digit calculation/validation.This routine is based on the ISO 7064 Mod 97,10 check digit calculation routine.
The two check digit characters in a IBAN number are the third and fourth characters in the code. For check digit calculation/validation the first four characters are moved to the end of the code. So
CCDDnnnnnnnbecomesnnnnnnnCCDD(whereCCis the country code andDDis the check digit). For check digit calculation the check digit value should be set to zero (i.e.CC00nnnnnnnin this example.Note: the class does not check the format of the IBAN number, only the check digits.
For further information see Wikipedia - IBAN number.
- Since:
- Validator 1.4
- Version:
- $Revision: 1713572 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static CheckDigitIBAN_CHECK_DIGITSingleton IBAN Number Check Digit instanceprivate static longMAXprivate static longMODULUSprivate static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description IBANCheckDigit()Construct Check Digit routine for IBAN Numbers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcalculate(java.lang.String code)Calculate the Check Digit for an IBAN code.private intcalculateModulus(java.lang.String code)Calculate the modulus for a code.booleanisValid(java.lang.String code)Validate the check digit of an IBAN code.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
IBAN_CHECK_DIGIT
public static final CheckDigit IBAN_CHECK_DIGIT
Singleton IBAN Number Check Digit instance
-
MAX
private static final long MAX
- See Also:
- Constant Field Values
-
MODULUS
private static final long MODULUS
- See Also:
- Constant Field Values
-
-
Method Detail
-
isValid
public boolean isValid(java.lang.String code)
Validate the check digit of an IBAN code.- Specified by:
isValidin interfaceCheckDigit- Parameters:
code- The code to validate- Returns:
trueif the check digit is valid, otherwisefalse
-
calculate
public java.lang.String calculate(java.lang.String code) throws CheckDigitExceptionCalculate the Check Digit for an IBAN code.Note: The check digit is the third and fourth characters and is set to the value "
00".- Specified by:
calculatein interfaceCheckDigit- Parameters:
code- The code to calculate the Check Digit for- Returns:
- The calculated Check Digit as 2 numeric decimal characters, e.g. "42"
- Throws:
CheckDigitException- if an error occurs calculating the check digit for the specified code
-
calculateModulus
private int calculateModulus(java.lang.String code) throws CheckDigitExceptionCalculate the modulus for a code.- Parameters:
code- The code to calculate the modulus for.- Returns:
- The modulus value
- Throws:
CheckDigitException- if an error occurs calculating the modulus for the specified code
-
-