diff --git a/CommunityToolkit.Common/Extensions/StringExtensions.cs b/CommunityToolkit.Common/Extensions/StringExtensions.cs index 2e893221..a94135a0 100644 --- a/CommunityToolkit.Common/Extensions/StringExtensions.cs +++ b/CommunityToolkit.Common/Extensions/StringExtensions.cs @@ -68,6 +68,17 @@ public static bool IsDecimal([NotNullWhen(true)] this string? str) return decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out _); } + /// + /// Determines whether a string is valid as a currency. + /// + /// The string to test. + /// The culture to check against. If left null, is used. + /// true for a valid currency; otherwise, false. + public static bool IsCurrency([NotNullWhen(true)] this string? str, CultureInfo? culture = null) + { + return decimal.TryParse(str, NumberStyles.Currency, culture ?? CultureInfo.CurrentCulture, out _); + } + /// /// Determines whether a string is a valid integer. ///