16 lines
581 B
C#
16 lines
581 B
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace StandManager.Utils;
|
|
|
|
public class EmailCheckAttribute : ValidationAttribute
|
|
{
|
|
protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
|
|
{
|
|
var str = value as string;
|
|
if (string.IsNullOrEmpty(str)) return ValidationResult.Success;
|
|
|
|
return !Regex.IsMatch(str, "^[\\w-\\.\\+]+@([\\w-]+\\.)+[\\w-]{2,}$") ? new ValidationResult(ErrorMessage ?? "Inserire un indirizzo Email valido") : ValidationResult.Success;
|
|
}
|
|
}
|