Below is a Java code to validate fund ISIN code..
import java.util.regex.Pattern;
public class TestISINCode{
public static void main(String args[]){
System.out.println(TestISINCode.checkIsinCode("GB00B0XWN709"));
}
private static final Pattern ISIN_PATTERN = Pattern.compile("[A-Z]{2}([A-Z0-9]){9}[0-9]");
public static boolean checkIsinCode(String isin) {
if (isin == null) {
return false;
}
if (!ISIN_PATTERN.matcher(isin).matches()) {
return false;
}
StringBuffer digits = new StringBuffer();
for (int i = 0; i < 11; i++) {
digits.append(Character.digit(isin.charAt(i), 36));
}
digits.reverse();
int sum = 0;
for (int i = 0; i < digits.length(); i++) {
int digit = Character.digit(digits.charAt(i), 36);
if (i % 2 == 0) {
digit *= 2;
}
sum += digit / 10;
sum += digit % 10;
}
int checkDigit = Character.digit(isin.charAt(11), 36);
int tensComplement = (sum % 10 == 0) ? 0 : ((sum / 10) + 1) * 10 - sum;
return checkDigit == tensComplement;
}
}
import java.util.regex.Pattern;
public class TestISINCode{
public static void main(String args[]){
System.out.println(TestISINCode.checkIsinCode("GB00B0XWN709"));
}
private static final Pattern ISIN_PATTERN = Pattern.compile("[A-Z]{2}([A-Z0-9]){9}[0-9]");
public static boolean checkIsinCode(String isin) {
if (isin == null) {
return false;
}
if (!ISIN_PATTERN.matcher(isin).matches()) {
return false;
}
StringBuffer digits = new StringBuffer();
for (int i = 0; i < 11; i++) {
digits.append(Character.digit(isin.charAt(i), 36));
}
digits.reverse();
int sum = 0;
for (int i = 0; i < digits.length(); i++) {
int digit = Character.digit(digits.charAt(i), 36);
if (i % 2 == 0) {
digit *= 2;
}
sum += digit / 10;
sum += digit % 10;
}
int checkDigit = Character.digit(isin.charAt(11), 36);
int tensComplement = (sum % 10 == 0) ? 0 : ((sum / 10) + 1) * 10 - sum;
return checkDigit == tensComplement;
}
}