예제 #1
0
        /// <summary>
        /// Validates the account number as a Type 1 account. Will try to fix any errors in the account number. If not being able to
        /// fix an incomplete account number an exception will be thrown.
        /// </summary>
        /// <param name="clearingNumber">The clearing number should be 4 digits.</param>
        /// <param name="accountNumber">The account number should be max 7 digits. Will be leftpadded with zeroes if shorter.</param>
        private static void ValidateType1(string clearingNumber, ref string accountNumber)
        {
            // Def. Type 1 Account (BGC: Type 1, Remark 1)
            // (1) The clearing number should be 4 digits.
            // (2) The account number should be 7 digits (if less than 7 characters, leftpad with zeroes).
            // (3) Checksum calculation is made on the clearing number with the exception of the first digit, and seven digits of the actual account number.

            // Clearing number should be 4 digits
            if (clearingNumber.Length != 4)
            {
                throw new ArgumentException(
                          string.Format("clearingNumber is {0} characters long. Expected 4 characters.",
                                        clearingNumber.Length));
            }

            // Account numbers with less than 7 digits should be leftpadded with zeroes.
            accountNumber = accountNumber.PadLeft(7, '0');

            // Acount number should be 7 digits
            if (accountNumber.Length != 7)
            {
                throw new ArgumentException(
                          string.Format("accountNumber is {0} characters long. Expected 7 characters.",
                                        accountNumber.Length));
            }

            // Checksum calculation is made on the clearing number with the exception of the first digit,
            // and seven digits of the actual account number.
            string checkValue = string.Concat(clearingNumber.Substring(1, 3), accountNumber);

            if (!ModulusCheck.Mod11(checkValue))
            {
                throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 1)."));
            }
        }
예제 #2
0
        /// <summary>
        /// Validates the account number as a Type 4 account. Will try to fix any errors in the account number. If not being able to
        /// fix an incomplete account number an exception will be thrown.
        /// </summary>
        /// <param name="clearingNumber">The clearing number shoukld be 4 digits.</param>
        /// <param name="accountNumber">The account number should be max 9 characters. Will be leftpadded with zeroes if shorter.</param>
        private static void ValidateType4(string clearingNumber, ref string accountNumber)
        {
            // Def. Type 4 Account (BGC: Type 2, Remark 2)
            // (1) The clearing number should be 4 digits, and is not a part of the account number.
            // (2) The account number should be 9 digits (if less than 9 characters, leftpaded with zeroes).
            // (3) Checksum calculations is made on the last 9 digits in the account number (modulus 11 check).

            // Clearing number should be 4 digits
            if (clearingNumber.Length != 4)
            {
                throw new ArgumentException(
                          string.Format("clearingNumber is {0} characters long. Expected 4 characters.",
                                        clearingNumber.Length));
            }

            // Account numbers with less than 9 digits should be leftpadded with zeroes.
            accountNumber = accountNumber.PadLeft(9, '0');
            if (accountNumber.Length != 9)
            {
                throw new ArgumentException(
                          string.Format("accountNumber is {0} characters long. Expected 9 characters.",
                                        accountNumber.Length));
            }

            if (!ModulusCheck.Mod11(accountNumber))
            {
                throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 4)."));
            }
        }