示例#1
0
 /// <summary>
 /// Validates the member.
 /// </summary>
 /// <param name="member">The member.</param>
 /// <param name="maxLength">Length of the max.</param>
 /// <param name="validationErrors">The validation errors.</param>
 /// <param name="missingCode">The missing code.</param>
 /// <param name="tooLongCode">The too long code.</param>
 public static void ValidateMember(string member, int maxLength, ICollection <ValidationError> validationErrors, ValidationErrorCodes missingCode, ValidationErrorCodes tooLongCode)
 {
     if (String.IsNullOrEmpty(member))
     {
         validationErrors.AddValidationErrorMessage(missingCode);
     }
     else
     if (member.Length > maxLength)
     {
         validationErrors.AddValidationErrorMessage(tooLongCode);
     }
 }
示例#2
0
        /// <summary>
        /// Determines whether the specified account number is valid. The account number
        /// is given as a full number including the hypothetical check digit.
        /// validation steps:
        /// * bank code can have 4 digits max
        /// * branch code can have 4 digits max
        /// * account number can have 13 digits max (including 2 check digits)
        /// * check digit is valid
        /// </summary>
        /// <param name="accountNumber">The account number including the hypothetical check digit.</param>
        /// <param name="validationErrors">Collection is filled up with the validation error messages</param>
        /// <returns>
        ///   <c>true</c> if the specified account number is valid; otherwise, <c>false</c>.
        /// </returns>
        public bool Validate(NationalAccountNumber accountNumber, ICollection <ValidationError> validationErrors)
        {
            if (accountNumber == null)
            {
                throw new ArgumentNullException("accountNumber", "Please provide an account number.");
            }

            validationErrors = validationErrors ?? new List <ValidationError>();

            var portugalAccountNumber = new PortugalAccountNumber(accountNumber);

            ValidationMethodsTools.ValidateMember(portugalAccountNumber.AccountNumber, 13, validationErrors, ValidationErrorCodes.AccountNumberMissing, ValidationErrorCodes.AccountNumberTooLong);
            ValidationMethodsTools.ValidateMember(portugalAccountNumber.BankCode, 4, validationErrors, ValidationErrorCodes.BankCodeMissing, ValidationErrorCodes.BankCodeTooLong);
            ValidationMethodsTools.ValidateMember(portugalAccountNumber.Branch, 4, validationErrors, ValidationErrorCodes.BranchCodeMissing, ValidationErrorCodes.BranchCodeTooLong);

            if (validationErrors.Count > 0)
            {
                return(false);
            }

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

            if (!validationMethod.IsValid(fullAccountNumber))
            {
                validationErrors.AddValidationErrorMessage("The validation of the check digits failed.");
            }

            return(validationErrors.Count == 0);
        }
        /// <summary>
        /// Determines whether the specified account number is valid. The account number
        /// is given as a full number including the hypothetical check digit.
        /// validation steps:
        /// * bank code can have 3 digits max
        /// * account number can have 9 digits max (including the 2 check digits)
        /// * check digits are valid
        /// </summary>
        /// <param name="accountNumber">The account number including the hypothetical check digit.</param>
        /// <param name="validationErrors">Collection is filled up with the validation error messages</param>
        /// <returns>
        ///   <c>true</c> if the specified account number is valid; otherwise, <c>false</c>.
        /// </returns>
        public bool Validate(NationalAccountNumber accountNumber, ICollection <ValidationError> validationErrors)
        {
            if (accountNumber == null)
            {
                throw new ArgumentNullException("accountNumber", "Please provide an account number.");
            }

            validationErrors = validationErrors ?? new List <ValidationError>();

            var belgiumAccountNumber = new BelgiumAccountNumber(accountNumber);

            ValidationMethodsTools.ValidateMember(belgiumAccountNumber.AccountNumber, 9, validationErrors, ValidationErrorCodes.AccountNumberMissing, ValidationErrorCodes.AccountNumberTooLong);
            ValidationMethodsTools.ValidateMember(belgiumAccountNumber.BankCode, 3, validationErrors, ValidationErrorCodes.BankCodeMissing, ValidationErrorCodes.BankCodeTooLong);

            if (validationErrors.Count > 0)
            {
                return(false);
            }

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

            if (!validationMethod.IsValid(accountNumberWithBankCode))
            {
                validationErrors.AddValidationErrorMessage("The validation of the check digits failed.");
            }

            return(validationErrors.Count == 0);
        }