Files
isn/src/isn.abst/SafeNameAttribute.cs
2023-04-17 01:20:42 +01:00

20 lines
531 B
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace isnd.Attributes
{
public class SafeNameAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
if (!(value is string))
return false;
string str = value as string;
if (str.Length>126) return false;
if (str.Any(c => !char.IsLetterOrDigit(c)
&& !"-_.".Contains(c))) return false;
return true;
}
}
}