question

MJ-8053 avatar image
0 Votes"
MJ-8053 asked MJ-8053 commented

AspNet.Identity PasswordValidator

I have both English and Spanish version of the website. Is there a way to have the validation message appear in Spanish when on the Spanish Version?

I have altered the RegisterViewModel

 public class RegisterViewModel
 {
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "FirstNameRequired")]
     [Display(Name = "FirstName", ResourceType = typeof(Registration))]
     [StringLength(30, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "FirstNameLength")]
     public string FirstName { get; set; }
    
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "LastNameRequired")]
     [Display(Name = "LastName", ResourceType = typeof(Registration))]
     [StringLength(50, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "LastNameLength")]
     public string LastName { get; set; }
    
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "EmailRequired")]
     [EmailAddress]
     [Display(Name = "Email", ResourceType = typeof(Registration))]
     public string Email { get; set; }
    
     [StringLength(100, ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordMinimum", MinimumLength = 8)]
     [DataType(DataType.Password)]
     [Display(Name = "Password", ResourceType = typeof(Registration))]
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordRequired")]
     public string Password { get; set; }
    
     [DataType(DataType.Password)]
     [Display(Name = "PasswordConfirm", ResourceType = typeof(Registration))]
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "PasswordConfirmRequired")]
     [Compare("Password", ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "Compare")]
     public string ConfirmPassword { get; set; }
    
     [Display(Name = "Telephone", ResourceType = typeof(Registration)), Phone]
     [Required(ErrorMessageResourceType = typeof(Registration), ErrorMessageResourceName = "TelephoneRequired")]
     [DataType(DataType.PhoneNumber)]
     public string PhoneNumber { get; set; }
     
     public string CaptchaCode { get; set; }
 }

but don't know how to change the message when it is missing a requirement such as

Passwords must have at least one uppercase ('A'-'Z')

dotnet-aspnet-mvc
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

XuDongPeng-MSFT avatar image
0 Votes"
XuDongPeng-MSFT answered MJ-8053 commented

Hi @MJ-8053 ,

Based on your description, if you just want to show error messages in Spanish, you can try the following steps:

  1. Install the identity localized package in Package Manager Console : PM> Install-Package Microsoft.AspNet.Identity.Core.es.

  2. Add the configuration code to the Web.config:

<system.web>
      <globalization culture="es-ES" uiCulture="es" />
  </system.web>

Then you can check the validation message like this:

241270-image.png

If I misunderstood anything about your requirement, just let me know.

Best regards,
Xudong Peng


If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


image.png (23.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

many thanks

0 Votes 0 ·

i should mention that instead of just showing in spanish they also needed to be in english for the english speaking side so in the config it is

 <system.web>
    <globalization enableClientBasedCulture="true"/>
 </system.web>






0 Votes 0 ·