James Hao
James Hao

Reputation: 905

How to support unicode for UserName?

I add a register feature that needs unicode support for UserName (Chinese for now). When I input Chinese UserName, there is an error window that pops up:

User name xxxxx is invalid, can only contain letters or digits.

I search source code and do not find any validator or filter for that. I check the SQL Server schema, the UserName type is nvarchar(32), which is unicode enabled.

Could anyone please tell me how to add unicode support for that field? Thanks.

Upvotes: 2

Views: 703

Answers (1)

aaron
aaron

Reputation: 43073

This is the default behaviour of ASP.NET (Core) Identity.

You can do the following to disable validation.

ASP.NET Core Identity

IdentityRegistrar.cs:

return services.AddAbpIdentity<Tenant, User, Role>(options =>
{
    options.User.AllowedUserNameCharacters = null;
})

ASP.NET Identity (MVC 5)

UserManager.cs:

(UserValidator as Microsoft.AspNet.Identity.UserValidator<User, long>)
    .AllowOnlyAlphanumericUserNames = false;

Upvotes: 3

Related Questions