From fe7350592749c8b0bf43370527a2cde652b00d76 Mon Sep 17 00:00:00 2001 From: Arlo Date: Mon, 20 Dec 2021 18:48:45 +0000 Subject: [PATCH] Added IsCurrency to StringExtensions #72 --- .../Extensions/StringExtensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CommunityToolkit.Common/Extensions/StringExtensions.cs b/CommunityToolkit.Common/Extensions/StringExtensions.cs index 2e893221..1505aa04 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 a 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. ///