Created
September 9, 2012 20:52
-
-
Save kostrse/3687221 to your computer and use it in GitHub Desktop.
CheckAccountNumber - checks checksum for Russian bank account number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static bool CheckAccountNumber(string bankNumber, string accountNumber) | |
{ | |
int[] mask = new[] { 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1, 3, 7, 1 }; | |
if (bankNumber.Length < 3) | |
{ | |
Console.WriteLine("Incorrect bank number."); | |
return false; | |
} | |
if (accountNumber.Length != 20) | |
{ | |
Console.WriteLine("Incorrect account number."); | |
return false; | |
} | |
string checkNumber = bankNumber.Substring(bankNumber.Length - 3, 3) + accountNumber; | |
int summ = 0; | |
for (int i = 0; i < checkNumber.Length; i++) | |
{ | |
int digitNumber = int.Parse(checkNumber.Substring(i, 1), CultureInfo.InvariantCulture); | |
int digitMask = mask[i]; | |
summ += digitNumber * digitMask % 10; | |
} | |
return summ % 10 == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment