Answer the question
In order to leave comments, you need to log in
How to do password validation with regular expressions in ASP.NET MVC project?
I am learning asp.net mvc
There is a model:
public class LoginViewModel
{
[Display(Name = "Логин")]
[Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(Resources.Resources))]
public string Login { get; set; }
[Display(Name = "Пароль")]
[DataType(DataType.Password)]
[Required(ErrorMessageResourceName = "RequiredField", ErrorMessageResourceType = typeof(Resources.Resources))]
[RegularExpression("/(?=.*[0-9])(?=.*[[email protected]#$%^&*])(?=.*[a-z])(?=.*[A-Z])[[email protected]#$%^&*]", ErrorMessageResourceName = "PasswordIsNotValid", ErrorMessageResourceType = typeof(Resources.Resources))]
public string Password { get; set; }
}
<div class="common-row">
<label class="common-label">
@Resources.NewPassword
</label>
@Html.TextBoxFor(model => model.Password, new { @class = "common-input", type = "password" })
<div class="error__input">
@Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
</div>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question