This Java library extends commons-validator and implements algorithms specified in ISO/IEC 7064 and LUHN which is defined in ISO/IEC 7812-1 Annex B.
The standard-validator jar calculates/validates
- credit card numbers (LUHN)
- all IBANs (ISO/IEC 7064:MOD 97-10)
- US Routing transit number (MOD-10)
- Creditor Reference (ISO-11649)
- ISIN (US-CUSIP and GB-SEDOL)
- EAN/UPC, ISBNs and ISSNs (MOD-10)
- all european VAT ID numbers and Tax numbers
- french SIREN and SIRET numbers (LUHN)
- chemical numbers CAS, EC index and EC-number
- IMO vessel number (MOD-10)
- german Leitweg-ID (ISO/IEC 7064:MOD 97-10)
- Legal Entity Identifier (ISO-17442)
calculates/validates ISO/IEC 7064 check characters.
The algorithms include all pure systems plus the pure polynomial implementations of:
- ISO/IEC 7064, MOD 11-2 for numeric strings with one check digit or the supplementary check character "X"
- ISO/IEC 7064, MOD 37-2 for alphanumeric strings with one check digit or letter or the supplementary check character "*"
- ISO/IEC 7064, MOD 97-10 for numeric strings with two check digits
- ISO/IEC 7064, MOD 661-26 for alphabetic strings with two check letters
- ISO/IEC 7064, MOD 1271-36 for alphanumeric strings with two check digits or letters
This is a full implementation of the ISO/IEC standard. Also hybrid systems are implemeted:
- ISO/IEC 7064, MOD 11,10 for numeric strings with one check digit
- ISO/IEC 7064, MOD 27,26 for alphabetic strings with one check letter
- ISO/IEC 7064, MOD 37,36 for alphanumeric strings with one check digit or letter
There is no standard for the Luhn algorithm. It is specified in Annex of ISO/IEC 7812 for Identification cards. Here a screenshot:
<!-- https://mvnrepository.com/artifact/io.github.homebeaver/standard-validator -->
<dependency>
<groupId>io.github.homebeaver</groupId>
<artifactId>standard-validator</artifactId>
<version>2.10.4</version>
</dependency>The modules are originally planned to be part of Apache commons-validator
Java example:
CheckDigit numericCheck = IsoIecPure11System.getInstance();
String checkDigit = numericCheck.calculate("123456");
boolean isValid = numericCheck.isValid("123456X");A more practical example (create a valid Structured Creditor Reference and check it):
String createRFCreditorReference(final String cr) {
System.out.println("createRFCreditorReference from [" + cr + "]");
CheckDigit checkDigit = RFCreditorReferenceCheckDigit.getInstance();
String cd = "00"; // check digit to start with
try {
cd = checkDigit.calculate(RFCreditorReferenceCheckDigit.RF + cd + cr);
return RFCreditorReferenceCheckDigit.RF + cd + cr;
} catch (CheckDigitException ex) {
System.out.println("failed to create RFCreditorReference : " + ex.getMessage());
}
return null;
}
final String cr = "InvNo4711date25DEC31"; //Maximum is 21 chars
String validRFcr = createRFCreditorReference(cr);
boolean isValid = RFCreditorReferenceValidator.getInstance().isValid(validRFcr);
System.out.println("created RFCreditorReference " + validRFcr + " is " + (isValid ? "OK" : "NOT valid"));
/* result is:
createRFCreditorReference from [InvNo4711date25DEC31]
created RFCreditorReference RF07InvNo4711date25DEC31 is OK
*/