Esempio n. 1
0
        /// <summary>
        /// Validates the account number as a Type 3 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 10 digits. Will be leftpadded with zeroes if shorter.</param>
        private static void ValidateType3(string clearingNumber, ref string accountNumber)
        {
            // Def. Type 3 Account (BGC: Type 2, Remark 1)
            // (1) The clearing number should be 4 digits, and is not a part of the account number.
            // (2) The account number should be 10 digits (if less than 10 charcters, leftpaded with zeroes).
            // (3) Checksum calculation is made on the last 10 digits in the account number (modulus 10 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 10 digits should be leftpadded with zeroes.
            accountNumber = accountNumber.PadLeft(10, '0');

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

            if (!ModulusCheck.Mod10(accountNumber))
            {
                throw new ArgumentException(string.Format("accountNumber has an invalid checksum (Type 3)."));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the account number as a Type 5 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"></param>
        /// <param name="accountNumber"></param>
        private static void ValidateType5(string clearingNumber, ref string accountNumber)
        {
            // Def. Type 5 Account (BGC: Type 2, Remark 3)
            // (1) The clearing number should be 4-5 digits, and is not a part of the account number.
            // (2) The account number should be 7-10 digits (no padding).
            // (3) Checksum calculations is made on the last 7-10 digits in the account number (modulus 10 check).

            if (accountNumber.Length > 10 || accountNumber.Length < 7)
            {
                throw new ArgumentException(
                          string.Format("accountNumber is {0} characters long. Expected 7-10 characters.",
                                        accountNumber.Length));
            }

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