isn/src/isnd/Controllers/SafeNameAttribute.cs
Paul Schneider 476d35ae8a refact
2021-07-05 12:55:52 +01:00

20 lines
No EOL
533 B
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace isn.Controllers
{
internal 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;
}
}
}