Esempio n. 1
0
        /// <inheritdoc />
        public ValidationRuleResult Validate(ValidationRuleContext context)
        {
            string iban   = context.Value;
            int    length = iban.Length;
            var    buffer = new char[length];

            // Reorder (first 4 chars at end).
            iban.CopyTo(4, buffer, 0, length - 4);
            iban.CopyTo(0, buffer, length - 4, 4);

            return(_checkDigitsCalculator.Compute(buffer) == ExpectedCheckDigit
                ? ValidationRuleResult.Success
                : new InvalidCheckDigitsResult());
        }
        /// <summary>
        /// Validates a BBAN for valid national check digits.
        /// </summary>
        public virtual bool Validate(string bban)
        {
            string checkString = GetCheckString(bban);

            try
            {
                int computedCheckDigits = _checkDigitsCalculator.Compute(checkString.ToCharArray());

                return(GetExpectedCheckDigits(bban) == computedCheckDigits);
            }
            catch (ArgumentException)
            {
                return(false);
            }
            catch (InvalidTokenException)
            {
                return(false);
            }
        }