refactor: massive refactor input elements, step 1/3
This commit is contained in:
1 parent
1154eabd8d
commit
99d2fafb72
35 files changed
+1213
-1460
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Tools;
|
||||
|
||||
public class RegexRule : ValidationRule
|
||||
{
|
||||
public TextType Type { get; set; }
|
||||
|
||||
public string Pattern { get; set; }
|
||||
|
||||
public string ErrorContent { get; set; } = Properties.Langs.Lang.FormatError;
|
||||
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is not string text)
|
||||
{
|
||||
return CreateErrorValidationResult();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Pattern))
|
||||
{
|
||||
if (!text.IsKindOf(Pattern))
|
||||
{
|
||||
return CreateErrorValidationResult();
|
||||
}
|
||||
}
|
||||
else if (Type != TextType.Common)
|
||||
{
|
||||
if (!text.IsKindOf(Type))
|
||||
{
|
||||
return CreateErrorValidationResult();
|
||||
}
|
||||
}
|
||||
|
||||
return ValidationResult.ValidResult;
|
||||
}
|
||||
|
||||
private ValidationResult CreateErrorValidationResult()
|
||||
{
|
||||
return new ValidationResult(false, ErrorContent);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user