Compare password and confirm password in ASP.Net MVC

后端 未结 6 1184
遥遥无期
遥遥无期 2021-02-07 06:32

Is it possible to compare confirm password textbox\'s text with @Html.PasswordFor(model=>model.Password)?

@using (Html.BeginForm())
{
    

        
6条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-07 07:04

    It is possible to compare your "Password" text box value with a "Confirm Password" text box value both on client side and server side. The solutions given by others is for confirmation on server side. If you don't want to include "Confirm Password" in your model then you have to compare client side. This can be done through Javascript. Either you can manually write a code to compare or you can include the following script in your .cshtml file. (Assuming you are using Visual Studio to write your code).

    
    
    
    

    Then you should create a field like below:

     
    
    

    This will compare your "Password" text box with "Confirm Password" text box and also show an error message if the values in both text box don't match, without you having to write any additional code.

    Although, a good practice is to do both client side as well as server side validation.

提交回复
热议问题