Files
Shrlalgo.RvKits/ShrlAlgo.Toolkit.Mvvm/ValidationRules/UndefinedCharRules.cs

26 lines
780 B
C#

using System.Globalization;
using System.Windows.Controls;
namespace ShrlAlgo.Toolkit.Mvvm.ValidationRules
{
public class UndefinedCharRules : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
char[] chars = new[] { '\\', ':', '{', '}', '[', ']', '|', ';', '<', '>', '?', '`', '~' };
if (value != null)
{
foreach (var c in chars)
{
if (value.ToString().IndexOf(c) > -1)
{
return new(false, $"名称不能包含字符:'\\ : [ ] | {{}}; < > ? ` ~");
}
}
}
return ValidationResult.ValidResult;
}
}
}