Ejemplo n.º 1
0
        private bool ValidateNumber()
        {
            const int modValue  = 97;
            const int modResult = 1;

            var wholeString = string.Concat(Bban, CountryCode, Checksum.ToString(CultureInfo.InvariantCulture).PadLeft(ChecksumLength, '0'));

            var sb = new StringBuilder();

            for (var i = 0; i < wholeString.Length; ++i)
#if NET20
            { sb.Append(CharExtensions.GetNumericValue(wholeString[i])); }
#else
            { sb.Append(wholeString[i].GetNumericValue()); }
#endif

            var valuedString = sb.ToString();

#if !NET40
            // Little workaround for not having a BigInteger class.

            const int maxLength = 9;

            long currentSum = 0;
            while (valuedString.Length > 0)
            {
                string nextString;
                int    subStrLength;
                if (currentSum > 0)
                {
                    var sumStr = currentSum.ToString(CultureInfo.InvariantCulture);
                    subStrLength = maxLength - sumStr.Length;
                    subStrLength = Math.Min(subStrLength, valuedString.Length);
                    nextString   = sumStr + valuedString.Substring(0, subStrLength);
                }
                else
                {
                    subStrLength = Math.Min(maxLength, valuedString.Length);
                    nextString   = valuedString.Substring(0, subStrLength);
                }
                valuedString = valuedString.Remove(0, subStrLength);

                currentSum = long.Parse(nextString) % modValue;
            }
            return(currentSum % modValue == modResult);
#else
            // Since .NET 4.0 and above have a BigInteger class, we use that.
            var ibanValue = BigInteger.Parse(valuedString);
            return(ibanValue % modValue == modResult);
#endif
        }
Ejemplo n.º 2
0
        private static bool ValidateBban(string bban)
        {
            bban = bban.Trim();
            if (bban.Length > MaxBbanLength)
            {
                return(false);
            }
            for (var i = 0; i < bban.Length; ++i)
            {
#if NET20
                if (!char.IsDigit(bban[i]) && !CharExtensions.IsValidChar(bban[i]))
#else
                if (!char.IsDigit(bban[i]) && !bban[i].IsValidChar())
#endif
                { return(false); }
            }
            return(true);
        }