Please tell me how to apply compare validater for password and confirm password in ASP.NET MVC2. Please give me some good link or any sample.
Thanks
Please tell me how to apply compare validater for password and confirm password in ASP.NET MVC2. Please give me some good link or any sample.
Thanks
Hi Rajesh,
Compare validator will accept ControlToValidate
property that should be set to your confirm password control,ControlToCompare
property that should be set to your password control. DataType
property is also there to set the comparison datatype, and you can set it to true.
This sample is taken straight from the mvc2 template and the MvcMusicStore sample (on codeplex).
This sample assumes you are using strongly typed views.
[PropertiesMustMatch("NewPassword", "ConfirmPassword", ErrorMessage = "The new password and confirmation password do not match.")]
public class ChangePasswordModel
{
[Required]
[DataType(DataType.Password)]
[DisplayName("Current password")]
public string OldPassword { get; set; }
[Required]
[ValidatePasswordLength]
[DataType(DataType.Password)]
[DisplayName("New password")]
public string NewPassword { get; set; }
[Required]
[DataType(DataType.Password)]
[DisplayName("Confirm new password")]
public string ConfirmPassword { get; set; }
}