From 72aa78ebe2b57d0d38db07d83aa6bc73a68ea9c7 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Mon, 4 Dec 2023 16:56:40 -0800 Subject: [PATCH] Fix email validation error message Fix #14828 --- .../Email/EmailAddressAttribute.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Email/EmailAddressAttribute.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Email/EmailAddressAttribute.cs index 4314b4d145f..4ef66774cee 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Email/EmailAddressAttribute.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Email/EmailAddressAttribute.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; namespace OrchardCore.Email { @@ -12,20 +13,14 @@ public class EmailAddressAttribute : ValidationAttribute protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var emailAddressValidator = validationContext.GetService(); + var S = validationContext.GetService>(); - if (value == null) + if (value == null || emailAddressValidator.Validate(value.ToString())) { return ValidationResult.Success; } - if (emailAddressValidator.Validate(value.ToString())) - { - return ValidationResult.Success; - } - else - { - return new ValidationResult(ErrorMessage, new[] { nameof(Email) }); - } + return new ValidationResult(S["Invalid email address."], new[] { nameof(Email) }); } } }