2025-02-10 20:53:40 +08:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-09-22 11:05:41 +08:00
|
|
|
|
|
2025-02-10 20:53:40 +08:00
|
|
|
|
namespace ShrlAlgo.Toolkit.Mvvm.Attributes
|
2024-09-22 11:05:41 +08:00
|
|
|
|
{
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
|
|
|
|
|
|
public class UndefinedCharAttribute : ValidationAttribute
|
|
|
|
|
|
{
|
|
|
|
|
|
public UndefinedCharAttribute(params char[] chars)
|
|
|
|
|
|
{
|
|
|
|
|
|
Chars = chars;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public char[] Chars { get; }
|
|
|
|
|
|
|
|
|
|
|
|
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
//char[] chars = new[] { '\\', ':', '{', '}', '[', ']', '|', ';', '<', '>', '?', '`', '~' };
|
|
|
|
|
|
if (value != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var c in Chars)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (value.ToString().IndexOf(c) > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new ValidationResult($"输入字符不合法,名称不能包含字符:'\\ : [ ] | {{}}; < > ? ` ~");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|