I had a problem when I was doing a registration form using MVC3, where the user has to confirm the password and then using Data annotations attribute [Compare] to make sure that the password and confirm password was equal. But there is a problem if this attribute I think. When typed different password the page wasn’t validated. The solution was change a little bit the code in the jquery.validate.unobtrusive.js file:
element = $(options.form).find(":input[name=" + fullOtherName + "]")[0];
to
element = $(options.form).find(":input[name=" + fullOtherName.replace(".", "\\.") + "]")[0];
When you use the code below, everything I’ll be fine:
[DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; }
Solution source: http://connect.microsoft.com/VisualStudio/feedback/details/665793/jquery-unobtrusive-validate-equalto-fails-with-compare-attribute