diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/InfoElement.cs b/src/Shared/HandyControl_Shared/Controls/Attach/InfoElement.cs index 43b0ad00..139ed595 100644 --- a/src/Shared/HandyControl_Shared/Controls/Attach/InfoElement.cs +++ b/src/Shared/HandyControl_Shared/Controls/Attach/InfoElement.cs @@ -68,5 +68,17 @@ namespace HandyControl.Controls public static double GetMaxContentHeight(DependencyObject element) => (double) element.GetValue(MaxContentHeightProperty); + + /// + /// 正则表达式 + /// + public static readonly DependencyProperty RegexPatternProperty = DependencyProperty.RegisterAttached( + "RegexPattern", typeof(string), typeof(InfoElement), new PropertyMetadata(default(string))); + + public static void SetRegexPattern(DependencyObject element, string value) + => element.SetValue(RegexPatternProperty, value); + + public static string GetRegexPattern(DependencyObject element) + => (string) element.GetValue(RegexPatternProperty); } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs b/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs index fb3c4cd2..7bf61c36 100644 --- a/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs +++ b/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs @@ -1,5 +1,4 @@ using System; -using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -36,7 +35,7 @@ namespace HandyControl.Controls public bool IsError { - get => (bool) GetValue(IsErrorProperty); + get => (bool)GetValue(IsErrorProperty); set => SetValue(IsErrorProperty, value); } @@ -48,7 +47,7 @@ namespace HandyControl.Controls public string ErrorStr { - get => (string) GetValue(ErrorStrProperty); + get => (string)GetValue(ErrorStrProperty); set => SetValue(ErrorStrProperty, value); } @@ -60,7 +59,7 @@ namespace HandyControl.Controls public TextType TextType { - get => (TextType) GetValue(TextTypeProperty); + get => (TextType)GetValue(TextTypeProperty); set => SetValue(TextTypeProperty, value); } @@ -72,20 +71,10 @@ namespace HandyControl.Controls public bool ShowClearButton { - get => (bool) GetValue(ShowClearButtonProperty); + get => (bool)GetValue(ShowClearButtonProperty); set => SetValue(ShowClearButtonProperty, value); } - public static readonly DependencyProperty TextTypeCustomRegexPatternProperty = DependencyProperty.Register( - "TextTypeCustomRegexPattern", typeof(string), typeof(TextBox), new PropertyMetadata(null)); - - public string TextTypeCustomRegexPattern - { - get => (string)GetValue(TextTypeCustomRegexPatternProperty); - set => SetValue(TextTypeCustomRegexPatternProperty, value); - } - - public virtual bool VerifyData() { OperationResult result; @@ -100,10 +89,14 @@ namespace HandyControl.Controls { if (TextType != TextType.Common) { - if (TextType == TextType.Custom && !string.IsNullOrEmpty(TextTypeCustomRegexPattern)) - result = Regex.IsMatch(Text, TextTypeCustomRegexPattern) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); - else - result = Text.IsKindOf(TextType) ? OperationResult.Success() : OperationResult.Failed(Properties.Langs.Lang.FormatError); + var regexPattern = InfoElement.GetRegexPattern(this); + result = string.IsNullOrEmpty(regexPattern) + ? Text.IsKindOf(TextType) + ? OperationResult.Success() + : OperationResult.Failed(Properties.Langs.Lang.FormatError) + : Text.IsKindOf(regexPattern) + ? OperationResult.Success() + : OperationResult.Failed(Properties.Langs.Lang.FormatError); } else { diff --git a/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs b/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs index 450b3ec5..bb73cf6d 100644 --- a/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs +++ b/src/Shared/HandyControl_Shared/Data/Enum/TextType.cs @@ -22,7 +22,6 @@ namespace HandyControl.Data NDouble, Double, NnDouble, - NpDouble, - Custom + NpDouble } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index b447dd89..13900768 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -349,8 +349,8 @@ - - + + diff --git a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs index 3c9d7f3e..55677025 100644 --- a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs +++ b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimation.cs @@ -79,7 +79,7 @@ namespace HandyControl.Media.Animation { var geometryStr = defaultDestinationValue.ToString(CultureInfo.InvariantCulture); AnimationHelper.DecomposeGeometryStr(geometryStr, out _numbersTo); - _strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern); + _strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern); } UpdateValue(); @@ -150,7 +150,7 @@ namespace HandyControl.Media.Animation { var geometryStr = geometry.ToString(CultureInfo.InvariantCulture); AnimationHelper.DecomposeGeometryStr(geometryStr, out obj._numbersTo); - obj._strings = Regex.Split(geometryStr, RegularPatterns.DigitsPattern); + obj._strings = Regex.Split(geometryStr, RegexPatterns.DigitsPattern); obj.UpdateValue(); } } diff --git a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs index c58a8c3e..1db93792 100644 --- a/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs +++ b/src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs @@ -27,7 +27,7 @@ namespace HandyControl.Media.Animation return null; } - return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegularPatterns.DigitsPattern); + return _strings ??= Regex.Split(_keyFrames[0].Value.ToString(CultureInfo.InvariantCulture), RegexPatterns.DigitsPattern); } } diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/AnimationHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/AnimationHelper.cs index 851a8dc1..90e7a5ce 100644 --- a/src/Shared/HandyControl_Shared/Tools/Helper/AnimationHelper.cs +++ b/src/Shared/HandyControl_Shared/Tools/Helper/AnimationHelper.cs @@ -43,7 +43,7 @@ namespace HandyControl.Tools internal static void DecomposeGeometryStr(string geometryStr, out double[] arr) { - var collection = Regex.Matches(geometryStr, RegularPatterns.DigitsPattern); + var collection = Regex.Matches(geometryStr, RegexPatterns.DigitsPattern); arr = new double[collection.Count]; for (var i = 0; i < collection.Count; i++) { diff --git a/src/Shared/HandyControl_Shared/Tools/RegularJudgment.cs b/src/Shared/HandyControl_Shared/Tools/RegexJudgment.cs similarity index 74% rename from src/Shared/HandyControl_Shared/Tools/RegularJudgment.cs rename to src/Shared/HandyControl_Shared/Tools/RegexJudgment.cs index 725e11b3..1408d19b 100644 --- a/src/Shared/HandyControl_Shared/Tools/RegularJudgment.cs +++ b/src/Shared/HandyControl_Shared/Tools/RegexJudgment.cs @@ -7,9 +7,9 @@ namespace HandyControl.Tools /// /// 包含一些正则验证操作 /// - public static class RegularJudgment + public static class RegexJudgment { - private static readonly RegularPatterns RegularPatterns = new RegularPatterns(); + private static readonly RegexPatterns RegexPatterns = new RegexPatterns(); /// /// 判断字符串格式是否符合某种要求 @@ -32,7 +32,7 @@ namespace HandyControl.Tools { if (textType == TextType.Common) return true; return Regex.IsMatch(text, - RegularPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString()); + RegexPatterns.GetValue(Enum.GetName(typeof(TextType), textType) + "Pattern").ToString()); } /// @@ -42,7 +42,7 @@ namespace HandyControl.Tools /// 方法返回布尔值 public static bool IsEmail(this string email) { - return Regex.IsMatch(email, RegularPatterns.MailPattern); + return Regex.IsMatch(email, RegexPatterns.MailPattern); } /// @@ -55,11 +55,11 @@ namespace HandyControl.Tools { switch (ipType) { - case IpType.A: return Regex.IsMatch(ip, RegularPatterns.IpAPattern); - case IpType.B: return Regex.IsMatch(ip, RegularPatterns.IpBPattern); - case IpType.C: return Regex.IsMatch(ip, RegularPatterns.IpCPattern); - case IpType.D: return Regex.IsMatch(ip, RegularPatterns.IpDPattern); - case IpType.E: return Regex.IsMatch(ip, RegularPatterns.IpEPattern); + case IpType.A: return Regex.IsMatch(ip, RegexPatterns.IpAPattern); + case IpType.B: return Regex.IsMatch(ip, RegexPatterns.IpBPattern); + case IpType.C: return Regex.IsMatch(ip, RegexPatterns.IpCPattern); + case IpType.D: return Regex.IsMatch(ip, RegexPatterns.IpDPattern); + case IpType.E: return Regex.IsMatch(ip, RegexPatterns.IpEPattern); default: return false; } } @@ -71,7 +71,7 @@ namespace HandyControl.Tools /// 方法返回布尔值 public static bool IsIp(this string ip) { - return Regex.IsMatch(ip, RegularPatterns.IpPattern); + return Regex.IsMatch(ip, RegexPatterns.IpPattern); } /// @@ -81,7 +81,7 @@ namespace HandyControl.Tools /// 方法返回布尔值 public static bool IsChinese(this string str) { - return Regex.IsMatch(str, RegularPatterns.ChinesePattern); + return Regex.IsMatch(str, RegexPatterns.ChinesePattern); } /// @@ -91,7 +91,7 @@ namespace HandyControl.Tools /// 方法返回布尔值 public static bool IsUrl(this string str) { - return Regex.IsMatch(str, RegularPatterns.UrlPattern); + return Regex.IsMatch(str, RegexPatterns.UrlPattern); } } } \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Tools/RegularPatterns.cs b/src/Shared/HandyControl_Shared/Tools/RegexPatterns.cs similarity index 99% rename from src/Shared/HandyControl_Shared/Tools/RegularPatterns.cs rename to src/Shared/HandyControl_Shared/Tools/RegexPatterns.cs index 7226a6b0..5ac9663d 100644 --- a/src/Shared/HandyControl_Shared/Tools/RegularPatterns.cs +++ b/src/Shared/HandyControl_Shared/Tools/RegexPatterns.cs @@ -3,7 +3,7 @@ /// /// 包含一些正则验证所需要的字符串 /// - public sealed class RegularPatterns + public sealed class RegexPatterns { /// /// 邮件正则匹配表达式