23 lines
613 B
C#
23 lines
613 B
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Reflection.Metadata.Ecma335;
|
|
|
|
namespace OnlyPrompt.Backend.ApiModels.Validators
|
|
{
|
|
public class NoWhitespaceAttribute : ValidationAttribute
|
|
{
|
|
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
|
|
{
|
|
if(value is string strValue)
|
|
{
|
|
if(strValue.Any(c => char.IsWhiteSpace(c)))
|
|
return new ValidationResult($"{validationContext.DisplayName} should not contain any whitespace characters.");
|
|
|
|
return ValidationResult.Success;
|
|
}
|
|
|
|
return base.IsValid(value, validationContext);
|
|
}
|
|
}
|
|
|
|
}
|