/// <summary>Converts the string to an IBAN. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s"> /// A string containing an IBAN to convert. /// </param> /// <param name="formatProvider"> /// The specified format provider. /// </param> /// <param name="result"> /// The result of the parsing. /// </param> /// <returns> /// True if the string was converted successfully, otherwise false. /// </returns> public static bool TryParse(string s, IFormatProvider formatProvider, out InternationalBankAccountNumber result) { result = InternationalBankAccountNumber.Empty; if (string.IsNullOrEmpty(s)) { return(true); } var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture; if (Qowaiv.Unknown.IsUnknown(s, culture)) { result = Unknown; return(true); } if (Pattern.IsMatch(s)) { var str = Parsing.ClearSpacingToUpper(s); var country = Country.TryParse(str.Substring(0, 2)); Regex localizedPattern; if (str.Length > 11 && !country.IsEmptyOrUnknown() && (!LocalizedPatterns.TryGetValue(country, out localizedPattern) || localizedPattern.IsMatch(str))) { var validation = Alphanumeric.Replace(str.Substring(4) + str.Substring(0, 4), AlphanumericToNumeric); int sum = 0; int exp = 1; for (int pos = validation.Length - 1; pos >= 0; pos--) { sum += exp * AlphanumericAndNumericLookup.IndexOf(validation[pos]); exp = (exp * 10) % 97; } if ((sum % 97) == 1) { result = new InternationalBankAccountNumber() { m_Value = str }; return(true); } } } return(false); }