dotnet web sql business etc

16 березня, 2011

IBAN validation: C# implementation

IBAN validation checksum (a basic ISO 7064 mod 97-10 calculation where the remainder must equal 1).

Let's recall the steps of IBAN validation:

1.Move the four initial characters to the end of the string
2.Replace the letters in the string with digits, expanding the string as necessary, such that A=10, B=11 and Z=35.
3.Convert the string to an integer and mod-97 the entire number

And below is implementation of IBAN validation written in C#:
   public static bool ValidateIBAN(string ibanValue)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(ibanValue, "^[A-Z0-9]"))
            {
                ibanValue = ibanValue.Replace(" ", String.Empty);
                string iban =

                ibanValue.Substring(4, ibanValue.Length - 4) + ibanValue.Substring(0, 4);
                int asciiShift = 55;

                StringBuilder sb = new StringBuilder();
                foreach (char c in iban)
                {
                    int v;
                    if (Char.IsLetter(c))
                    {
                        v = c - asciiShift;
                    }
                    else
                    {
                        v = int.Parse(c.ToString());
                    }
                    sb.Append(v);
                }

                string checkSumString = sb.ToString();
                int checksum = int.Parse(checkSumString.Substring(0, 1));
                for (int i = 1; i < checkSumString.Length; i++)
                {
                    int v = int.Parse(checkSumString.Substring(i, 1));
                    checksum *= 10;
                    checksum += v;
                    checksum %= 97;
                }
                return checksum == 1;
            }
            else
            {
                return false;
            }

            }

Мітки: , ,

15 березня, 2011

IBAN (International Bank Account Number): definition and validation

IBAN is unique identifier of a customer bank account within the international bank systems.

Validation techniques:
1) has length of no more than 34 symbols
2) includes only big letters (A-Z), and digits (0-9), no slashes, spaces, hyphens, etc.
3) first two characters are country ISO code  mo(DE for Germany, FR for France, etc.)
4) satisfies a special validation algorithm

IBAN validation algorithm:
1) First 4 characters of the IBAN are transferred to the end of the string
2) All characters are transaformed to numeric representation as follows: digits are converted to corresponding numbers ("3" -> 3), A to 10, B to 11, .. and Z to 35.
3) The created number is divided by mod 97. If the remained 1 is obtained from the division then the IBAN is valid.

Мітки: ,