Reputation: 4337
I'm wondering if there is a library in java that validates a string against SEPA RF reference number in payments.
I can of course implement one of my own according rules defined by ISO 11649:2009(E) standard but I would not like to reinvent the wheel. I'm not able to goole any decent library about this. Do you know of any implementation for this?
Upvotes: 1
Views: 1208
Reputation: 11
Its more or less a simple calculation:
final String ref = "123456789012345678901"; //21 characters max
final String rf = "2715"; // RF converted to numbers
String rfAdd = "01"; // assuming 01 are the check digits
final BigInteger refint = new BigInteger(ref + rf + rfAdd);
int mod = refint.mod(new BigInteger("97"))
.intValue();
if (mod != 1) {
mod = 99 - mod; // set mod to correct check digits
}
rfAdd = String.format("%02d", mod); // correct the check digits
System.out.println("RF" + rfAdd + ref);
The result should be a valid Referencecode explained by this source
https://www.mobilefish.com/services/creditor_reference/creditor_reference.php
Upvotes: 1
Reputation: 859
There is one in an API for creating Swiss QR codes ("QR Rechnung"):
public static boolean isValidISO11649Reference(java.lang.String reference)
Validates if the string is a valid ISO 11649 reference number.
The string is checked for valid characters, valid length and a valid check digit. White space is ignored.
Parameters: reference - ISO 11649 creditor reference to validate
Returns: true if the creditor reference is valid, false otherwise
Upvotes: 1