java - 如何检查 IBAN 验证?

标签 java android banking bank iban

如何在 Java 中验证 IBAN(国际银行帐号)以在 Android 应用中使用?

The International Bank Account Number is an internationally agreed system of identifying bank accounts across national borders to facilitate the communication and processing of cross border transactions with a reduced risk of transcription errors.

最佳答案

private boolean isIbanValid(String iban) {

    int IBAN_MIN_SIZE = 15;
    int IBAN_MAX_SIZE = 34;
    long IBAN_MAX = 999999999;
    long IBAN_MODULUS = 97;

    String trimmed = iban.trim();

    if (trimmed.length() < IBAN_MIN_SIZE || trimmed.length() > IBAN_MAX_SIZE) {
        return false;
    }

    String reformat = trimmed.substring(4) + trimmed.substring(0, 4);
    long total = 0;

    for (int i = 0; i < reformat.length(); i++) {

        int charValue = Character.getNumericValue(reformat.charAt(i));

        if (charValue < 0 || charValue > 35) {
            return false;
        }

        total = (charValue > 9 ? total * 100 : total * 10) + charValue;

        if (total > IBAN_MAX) {
            total = (total % IBAN_MODULUS);
        }
    }

    return (total % IBAN_MODULUS) == 1;
}

关于java - 如何检查 IBAN 验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54884930/

相关文章:

java - HttpURLConnection 很慢

java - 需要 Firebase 每天仅返回一次日期,而不是在每条消息后返回日期

c++ - 如何在 C++ 中设置浮点变量的精度

database - 银行 overdraw 罚款是否与技术限制有关?

java - Java 中的类型转换/向下转换

javascript - 一键禁用按钮后是否有机会获得双击按钮?

android - 如何使用 Flutter 将 Braintree 集成到 iOS 或 Android 应用程序?

java - 输入不正确的字符时无法清除文本字段

java - 解码yuv420sp单像素版本