匈牙利 BBAN 验证
Posted
技术标签:
【中文标题】匈牙利 BBAN 验证【英文标题】:hungarian BBAN validation 【发布时间】:2017-03-09 23:53:43 【问题描述】:谁能告诉我如何验证匈牙利 BBAN 帐号? 在互联网上我只发现它是 24 个数字长度 并以格式
bbbs sssk cccc cccc cccc cccx
b = National bank code
s = Branch code
c = Account number
x = National check digit
但是如何计算 x = 国家校验位? 我试图通过 97 删除最后一个字符和模余数,但它不起作用 (有效帐号的结果不是 1)
提前感谢您的帮助
【问题讨论】:
您可能需要联系 匈牙利银行协会,因为计算您要查找的校验位的算法因国家/地区而异,他们是最有能力为您提供指导的组织在这个话题中。你可以找到他们的联系方式here。 【参考方案1】:我刚刚完成了匈牙利帐户验证功能。这是此功能的第一个版本,但运行良好。
public string sprawdzWegierskitempAccountNumber(string _accountNumberToCheck, bool _iban) //if iban is true then function result will be always IBAN (even if _accountNumberToCheck will be BBAN)
string _accountNumberCorrected = _accountNumberToCheck.Replace(" ", "");
_accountNumberCorrected = _accountNumberCorrected.Replace("-", "");
_accountNumberCorrected = _accountNumberCorrected.Replace("//", "");
_accountNumberCorrected = _accountNumberCorrected.Replace("\", "");
string _accountNumberCorrectedFirst = _accountNumberCorrected;
if (_accountNumberCorrected.Length == 16 || _accountNumberCorrected.Length == 24 || _accountNumberCorrected.Length == 28)
if (_accountNumberCorrected.Length == 28) //IBAN Account number
_accountNumberCorrected = _accountNumberCorrected.Substring(4, _accountNumberCorrected.Length - 4); //we don't need first four digits (HUxx)
string digitToMultiply = "9731";
int checkResult = 0;
//checking first part of account number
for (int i = 0; i <= 6; i++)
checkResult = checkResult + int.Parse(_accountNumberCorrected.ToCharArray()[i].ToString()) * int.Parse(digitToMultiply.ToCharArray()[i % 4].ToString());
checkResult = checkResult % 10;
checkResult = 10 - checkResult;
if (checkResult == 10)
checkResult = 0;
if (checkResult.ToString() != _accountNumberCorrected.ToCharArray()[7].ToString())
throw new Exception("Wrong account number");
else
//if first part it's ok then checking second part of account number
checkResult = 0;
for (int i = 8; i <= _accountNumberCorrected.Length-2; i++)
checkResult = checkResult + int.Parse(_accountNumberCorrected.ToCharArray()[i].ToString()) * int.Parse(digitToMultiply.ToCharArray()[i % 4].ToString());
checkResult = checkResult % 10;
checkResult = 10 - checkResult;
if (checkResult == 10)
checkResult = 0;
if (checkResult.ToString() != _accountNumberCorrected.ToCharArray()[_accountNumberCorrected.Length-1].ToString())
throw new Exception("Wrong account number");
string tempAccountNumber = _accountNumberCorrected + "173000";
var db = 0; var iban = 0;
var maradek = 0;
string resz = "", ibanstr = "", result = "";
while (true)
if (db == 0)
resz = tempAccountNumber.Substring(0, 9);
tempAccountNumber = tempAccountNumber.Substring(9, (tempAccountNumber.Length - 9));
else
resz = maradek.ToString();
resz = resz + tempAccountNumber.Substring(0, (9 - db));
tempAccountNumber = tempAccountNumber.Substring((9 - db), (tempAccountNumber.Length - 9 + db));
maradek = int.Parse(resz) % 97;
if (maradek == 0)
db = 0;
else
if (maradek < 10)
db = 1;
else
db = 2;
if ((tempAccountNumber.Length + db) <= 9)
break;
if (maradek != 0)
resz = maradek.ToString();
resz = resz + tempAccountNumber;
else
resz = tempAccountNumber;
maradek = int.Parse(resz) % 97; ;
iban = 98 - maradek;
if (iban < 10)
ibanstr = "0" + iban.ToString();
else ibanstr = iban.ToString();
if (_accountNumberCorrected.Length == 16)
_accountNumberCorrected = _accountNumberCorrected + "00000000";
_accountNumberCorrectedFirst = _accountNumberCorrectedFirst + "00000000";
if (_iban)
result = "HU" + ibanstr + _accountNumberCorrected;
else
result = _accountNumberCorrectedFirst;
return result;
else
throw new Exception("Wrong length of account number");
【讨论】:
以上是关于匈牙利 BBAN 验证的主要内容,如果未能解决你的问题,请参考以下文章