Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Currency validation to TextBoxExtensions #4469

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ public enum ValidationType
/// <summary>
/// Phone number validation
/// </summary>
PhoneNumber
PhoneNumber,

/// <summary>
/// Currency validation
/// </summary>
Currency
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Globalization;
using System.Text.RegularExpressions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -82,6 +83,9 @@ private static void ValidateTextBox(TextBox textBox, bool force = true)
case ValidationType.Characters:
regexMatch = textBox.Text.IsCharacterString();
break;
case ValidationType.Currency:
regexMatch = decimal.TryParse(textBox.Text, NumberStyles.Currency, CultureInfo.CurrentCulture, out _);
break;
}

if (!regexMatch && force)
Expand Down