From fe7350592749c8b0bf43370527a2cde652b00d76 Mon Sep 17 00:00:00 2001 From: Arlo Date: Mon, 20 Dec 2021 18:48:45 +0000 Subject: [PATCH 1/2] 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. /// From 482004c35dce46002aaf27016e828fb33af19e2b Mon Sep 17 00:00:00 2001 From: Arlo Date: Mon, 20 Dec 2021 18:49:09 +0000 Subject: [PATCH 2/2] Fixed a typo --- CommunityToolkit.Common/Extensions/StringExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommunityToolkit.Common/Extensions/StringExtensions.cs b/CommunityToolkit.Common/Extensions/StringExtensions.cs index 1505aa04..a94135a0 100644 --- a/CommunityToolkit.Common/Extensions/StringExtensions.cs +++ b/CommunityToolkit.Common/Extensions/StringExtensions.cs @@ -69,7 +69,7 @@ public static bool IsDecimal([NotNullWhen(true)] this string? str) } /// - /// Determines whether a string is a valid as a currency. + /// Determines whether a string is valid as a currency. /// /// The string to test. /// The culture to check against. If left null, is used.