From fa1878b3a0a49dbcc6eb62c0a5469dec4e4186dd Mon Sep 17 00:00:00 2001
From: Oleh Lesiv <31761482+olegL1337@users.noreply.github.com>
Date: Thu, 16 Dec 2021 13:44:22 +0200
Subject: [PATCH 1/2] currency validation support
---
.../Extensions/TextBox/TextBoxExtensions.Regex.Data.cs | 5 +++++
.../Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs | 6 ++++++
2 files changed, 11 insertions(+)
diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Data.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Data.cs
index 41cfaad55fa..c27e87e5d87 100644
--- a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Data.cs
+++ b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Data.cs
@@ -53,6 +53,11 @@ public enum ValidationType
///
Decimal,
+ ///
+ /// Currency validation
+ ///
+ Currency,
+
///
/// Text only validation
///
diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
index 1ffe92bd083..2da99554ccc 100644
--- a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
+++ b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
@@ -70,6 +70,12 @@ private static void ValidateTextBox(TextBox textBox, bool force = true)
case ValidationType.Decimal:
regexMatch = textBox.Text.IsDecimal();
break;
+ case ValidationType.Currency:
+ // @"(^\d*\.\d{2}$)" regex pattern to detect currency sign with currency value
+ // Mathes: $100.00, $100, $10.25
+ // Non-Matches: 100., $10.233, $10.
+ regexMatch = Regex.IsMatch(textBox.Text, @"(^\d*\.\d{2}$)");
+ break;
case ValidationType.Email:
regexMatch = textBox.Text.IsEmail();
break;
From 392b78396111a57416f3d4c1cc1d6c097d1e923b Mon Sep 17 00:00:00 2001
From: Oleh Lesiv <31761482+olegL1337@users.noreply.github.com>
Date: Thu, 16 Dec 2021 18:28:09 +0200
Subject: [PATCH 2/2] regex fix :)
---
.../Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
index 2da99554ccc..e15fd702c48 100644
--- a/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
+++ b/Microsoft.Toolkit.Uwp.UI/Extensions/TextBox/TextBoxExtensions.Regex.Internals.cs
@@ -74,7 +74,7 @@ private static void ValidateTextBox(TextBox textBox, bool force = true)
// @"(^\d*\.\d{2}$)" regex pattern to detect currency sign with currency value
// Mathes: $100.00, $100, $10.25
// Non-Matches: 100., $10.233, $10.
- regexMatch = Regex.IsMatch(textBox.Text, @"(^\d*\.\d{2}$)");
+ regexMatch = Regex.IsMatch(textBox.Text, @"^\$( )*\d*(.\d{1,2})?$");
break;
case ValidationType.Email:
regexMatch = textBox.Text.IsEmail();