/// <summary>
        /// Calculates the check digit.
        /// The account number is given without a check digit.
        /// </summary>
        /// <param name="accountNumber">The account number without a check digit.</param>
        /// <returns>
        /// The calculated check digit for the given account number
        /// </returns>
        public string CalculateCheckDigit(NationalAccountNumber accountNumber)
        {
            if (accountNumber == null)
            {
                throw new ArgumentNullException("accountNumber", "Please provide an account number.");
            }

            var belgiumAccountNumber = new BelgiumAccountNumber(accountNumber);

            if (String.IsNullOrEmpty(belgiumAccountNumber.AccountNumber))
            {
                throw new ArgumentException("The account number is missing.", "accountNumber");
            }
            if (String.IsNullOrEmpty(belgiumAccountNumber.BankCode))
            {
                throw new ArgumentException("The bank code is missing.", "accountNumber");
            }

            var accountNumberWithBankCode =
                String.Format("{0,3}{1,7}", belgiumAccountNumber.BankCode, belgiumAccountNumber.AccountNumber).Replace(' ', '0');

            var digits = validationMethod.CalculateCheckDigit(accountNumberWithBankCode);

            return(digits.Length < 2 ? "0" + digits : digits);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the check digit.
        /// The account number is given without a check digit.
        /// </summary>
        /// <param name="accountNumber">The account number without a check digit.</param>
        /// <returns>
        /// The calculated check digit for the given account number
        /// </returns>
        public string CalculateCheckDigit(NationalAccountNumber accountNumber)
        {
            if (accountNumber == null)
            {
                throw new ArgumentNullException("accountNumber", "Please provide an account number.");
            }

            var portugalAccountNumber = new PortugalAccountNumber(accountNumber);

            if (String.IsNullOrEmpty(portugalAccountNumber.BankCode))
            {
                throw new ArgumentException("The bank code is missing.", "accountNumber");
            }
            if (String.IsNullOrEmpty(portugalAccountNumber.Branch))
            {
                throw new ArgumentException("The branch code is missing.", "accountNumber");
            }
            if (String.IsNullOrEmpty(portugalAccountNumber.AccountNumber))
            {
                throw new ArgumentException("The account number is missing.", "accountNumber");
            }

            var fullAccountNumber =
                String.Format("{0,4}{1,4}{2,11}", portugalAccountNumber.BankCode, portugalAccountNumber.Branch, portugalAccountNumber.AccountNumber).Replace(' ', '0');

            return(validationMethod.CalculateCheckDigit(fullAccountNumber));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the check digit.
        /// The account number is given without a check digit.
        /// </summary>
        /// <param name="accountNumber">The account number without a check digit.</param>
        /// <returns>
        /// The calculated check digit for the given account number
        /// </returns>
        public string CalculateCheckDigit(NationalAccountNumber accountNumber)
        {
            if (accountNumber == null)
            {
                throw new ArgumentNullException("accountNumber", "Please provide an account number.");
            }

            var norwayAccountNumber = new NorwayAccountNumber(accountNumber);

            if (String.IsNullOrEmpty(norwayAccountNumber.BankCode))
            {
                throw new ArgumentException("The bank code is missing.", "accountNumber");
            }
            if (String.IsNullOrEmpty(norwayAccountNumber.AccountNumber))
            {
                throw new ArgumentException("The account number is missing.", "accountNumber");
            }

            var bankCodeWithBranch =
                String.Format("{0,4}{1,6}", norwayAccountNumber.BankCode, norwayAccountNumber.AccountNumber).Replace(' ', '0');

            return(validationMethod.CalculateCheckDigit(bankCodeWithBranch));
        }