To implement these steps: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
Also, a long is too small to hold the number. You need a BigInteger.
private boolean isIbanValid(String iban) {
// remove spaces
iban = iban.replace("\\s", "");
// make all uppercase
iban = iban.toUpperCase();
// check length - complicated, depends on country. Skipping for now.
// https://en.wikipedia.org/wiki/International_Bank_Account_Number#Structure
// move first four letters to the end
iban = iban.substring(4) + iban.substring(0,4);
// convert letters to digits
String total = "";
for (int i = 0; i < iban.length(); i++) {
int charValue = Character.getNumericValue(iban.charAt(i));
if (charValue < 0 || charValue > 35) {
return false;
}
total += charValue;
}
// Make BigInteger and check if modulus 97 is 1
BigInteger totalInt = new BigInteger(total);
return totalInt.mod(new BigInteger("97")).equals(BigInteger.ONE);
}