2021-06-22 23:03:38 +01:00
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2021-09-05 19:33:39 +01:00
|
|
|
namespace isnd.Attributes
|
2021-06-22 23:03:38 +01:00
|
|
|
{
|
2022-07-03 14:50:57 +01:00
|
|
|
public class SafeNameAttribute : ValidationAttribute
|
2021-06-22 23:03:38 +01:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|