MICR Tools Usage & Examples

Parsing a MICR String

Below is an example of how to use the MICR Parsing facilities to parse out a MICR string into it's relevant fields. This does not use any field validation facilities:

String testMICR = "c1234567c d026010757d 987654c";
MICRParser parser = new MICRParserImpl();
parser.setAmountSymbol("b");
parser.setDashSymbol("-");
parser.setOnUsSymbol("c");
parser.setTransitSymbol("d");

MICR parsedMicr = null;
try {
    parsedMicr = parser.parseMicrString(testMICR);
} catch(MICRParseException e) {
    // handle exception
}

If you want to use field validation, you need to add them to the parser for each field. MICR Tools comes with it's own set of validators, but you can also write your own (as long as it implements the com.minderupt.micrtools.FieldValidator interface):

MICRParser parser = new MICRParserImpl();
parser.setAmountSymbol("b");
parser.setDashSymbol("-");
parser.setOnUsSymbol("c");
parser.setTransitSymbol("d");

parser.setAmountFieldValidator(new AmountFieldValidator());

MICR parsedMicr = null;
try {
    parsedMicr = parser.parseMicrString(testMICR);
} catch(FieldValidationException fve) {
    // handle field validation exception
    System.err.println(fve.getFieldName() + " failed field validation:  " + fve.getMessage());
} catch(MICRParseException mpe) {
   // handle micr parse exception
}

Repairing a MICR String

TBD for repairing MICR with and without OCR