I have a VIEW call Change Password and I have a Current Password field, a New Password field, and a New Password Confirmation field.
All three fields pass through the same control filter for these passwords, the rule being that the password must be a required field and contain between 8 and 15 elements.
My problem is: when the filter is activated in the first password field (If the password is not within the rules), the error message appears in all 3 password fields, not only in the one that is being filled.
How can I isolate these components and cause the error message to only be displayed in the field that does not have the correct information?
<div class="row">
<div class="col-sm-12 col-sm-offset-4"><h2>Alterar senha do sistema</h2></div>
</div>
<br>
<div class="container">
<div class="middle">
<form>
<!--campo senha atual-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<label>Senha Atual</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" required>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<!-- nova senha-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<div class="input-group">
<label>Nova Senha</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" placeholder="Entre 8 e 15 caracteres" required>
</div>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<!--confirmar nova senha-->
<div class="row">
<div class="col-sm-3 col-sm-offset-4">
<div class="form-group">
<div class="input-group">
<label>Confirme a nova senha</label>
<input asp-for="Password" type="password" id="inputPassword" class="form-control" placeholder="Entre 8 e 15 caracteres" required>
</div>
@Html.ValidationMessageFor(model => model.Password)
</div>
</div>
</div>
<br>
<!--botao salvar-->
<div class="col-sm-1 col-sm-offset-4">
<button type="submit" class="btn btn-success btn-block">Salvar</button>
</div>
</form>
<!--link cancelar-->
<div class="col-sm-1">
<a href="#" class="forgot-password">Cancelar</a>
</div>
</div>
</div>
This is my filter for the password field
#region Senha
[Required(ErrorMessage = "Campo obrigatório")]
[StringLength(15, MinimumLength = 8, ErrorMessage = "Sua senha deve ter entre 8 e 15 caracteres.")]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
#endregion