Skip to content

Commit

Permalink
Fix email validation error message (#14832)
Browse files Browse the repository at this point in the history
Fix #14828
  • Loading branch information
MikeAlhayek authored Dec 5, 2023
1 parent 6b9463f commit a79e40f
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel.DataAnnotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;

namespace OrchardCore.Email
{
Expand All @@ -12,20 +13,14 @@ public class EmailAddressAttribute : ValidationAttribute
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var emailAddressValidator = validationContext.GetService<IEmailAddressValidator>();
var S = validationContext.GetService<IStringLocalizer<EmailAddressAttribute>>();

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) });
}
}
}

0 comments on commit a79e40f

Please sign in to comment.