title: Default validation message ASP.NET Core
body: <p>I created custom password validator to check the entering password by using my own regular expression. But when I testing it, the default error message is displayed first, and then mine. And I don’t understand how to remove this default message, so that only mine remains. My message is "Your password is incorrect".</p>
  
  <p>Error message:
  <a href="https://i.stack.imgur.com/j0cWb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j0cWb.png" alt="Default message with mine"></a></p>
  
  <p>And there is a code:</p>
  
  <p>Validator:</p>
  
  <pre><code>    {
  
          public Task&lt;IdentityResult&gt; ValidateAsync(UserManager&lt;User&gt; manager, User user, string password)
          {
              List&lt;IdentityError&gt; errors = new List&lt;IdentityError&gt;();
  
              string pattern = "^(?=^.{12,}$)(?=.*[0-9]+)(?=.*[A-Z]+)(?=.*[a-z]+)(?=.*[&amp;@^$%]+).*$";
  
              if (!Regex.IsMatch(password, pattern))
              {
                  return Task.FromResult(IdentityResult.Failed(new IdentityError
                  {
                      Code = "IncPass",
                      Description = "Your password is incorrect"
                  })) ;
              }
              return Task.FromResult(IdentityResult.Success);
          }
      }
  </code></pre>
  
  <p>Controller methods</p>
  
  <pre><code> [HttpGet]
          public IActionResult Register()
          {
              return View();
          }
          [HttpPost]
          public async Task&lt;IActionResult&gt; Register(RegisterViewModel model)
          {
              if (ModelState.IsValid)
              {
                  User user = new User { Email = model.Email, UserName = model.Email, Year = model.Year };
                  var result = await _userManager.CreateAsync(user, model.Password);
                  if (result.Succeeded)
                  {
                      return RedirectToAction("Index", "Home");
                  }
                  else
                  {
                      foreach (var error in result.Errors)
                      {
                          ModelState.AddModelError(string.Empty, error.Description);
                      }
                  }
              }
              return View(model);
          }
  </code></pre>
  
  <p>Startup</p>
  
  <pre><code>  services.AddIdentity&lt;User, IdentityRole&gt;()
                  .AddEntityFrameworkStores&lt;ApplicationContext&gt;()
                  .AddDefaultTokenProviders()
                  .AddPasswordValidator&lt;CustomPasswordValidator&gt;();
  </code></pre>