using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace UIStandardWebApi.EntityDto.ValidateRules { public class EmailAttribute : BaseAbstractAttribute { /// /// 验证邮箱格式 /// /// public EmailAttribute(string? messge) : base(messge) { } public override (bool, string?) DoValidate(object oValue) { if (oValue == null) { return (false, "邮箱地址不能为空"); } string str = @"^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(com|cn|net)$"; bool bResult = System.Text.RegularExpressions.Regex.IsMatch(oValue.ToString(), str); return bResult ? (true, string.Empty) : (false, Message); } } }