This commit is contained in:
2023-02-18 08:52:17 +01:00
parent 8a7d4ac906
commit 9719a0c0fd
137 changed files with 19057 additions and 0 deletions

View File

@ -0,0 +1,60 @@
using SocialPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels.ValidatorAttributes
{
[AttributeUsage(AttributeTargets.Property)]
public class NoWhiteSpacesAttribute : ValidationAttribute
{
const string errorMessageResourceName = "EmptySpacesNotAllowed";
readonly Type errorMessageResourceType = typeof(ErrorsResource);
readonly string[] spaces = new[] {
" ",
" ",
" ",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
" ",
};
public NoWhiteSpacesAttribute()
{
ErrorMessageResourceName = errorMessageResourceName;
ErrorMessageResourceType = errorMessageResourceType;
}
public override bool IsValid(object value)
{
var str = value?.ToString();
if (string.IsNullOrEmpty(str))
return true;
var hasWhiteSpace = false;
try
{
foreach (var space in spaces)
{
hasWhiteSpace = str.Contains(space);
if (hasWhiteSpace) break;
}
return !hasWhiteSpace;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
}
}