Skip to content

homebeaver/standard-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

ISO/IEC 7064

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:

LUHN

There is no standard for the Luhn algorithm. It is specified in Annex of ISO/IEC 7812 for Identification cards. Here a screenshot:

How to use

<!-- 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
 */