Skip to content

Commit fe73505

Browse files
authored
Added IsCurrency to StringExtensions #72
1 parent 9136501 commit fe73505

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

CommunityToolkit.Common/Extensions/StringExtensions.cs

+11
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public static bool IsDecimal([NotNullWhen(true)] this string? str)
6868
return decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out _);
6969
}
7070

71+
/// <summary>
72+
/// Determines whether a string is a valid as a currency.
73+
/// </summary>
74+
/// <param name="str">The string to test.</param>
75+
/// <param name="culture">The culture to check against. If left null, <see cref="CultureInfo.CurrentCulture"/> is used.</param>
76+
/// <returns><c>true</c> for a valid currency; otherwise, <c>false</c>.</returns>
77+
public static bool IsCurrency([NotNullWhen(true)] this string? str, CultureInfo? culture = null)
78+
{
79+
return decimal.TryParse(str, NumberStyles.Currency, culture ?? CultureInfo.CurrentCulture, out _);
80+
}
81+
7182
/// <summary>
7283
/// Determines whether a string is a valid integer.
7384
/// </summary>

0 commit comments

Comments
 (0)