Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
Forked from kouphax/gist:630234
Created September 25, 2017 00:49
Show Gist options
  • Save LSTANCZYK/47a6704504b7a37c94e7287f5eb09927 to your computer and use it in GitHub Desktop.
Save LSTANCZYK/47a6704504b7a37c94e7287f5eb09927 to your computer and use it in GitHub Desktop.
public class PasswordsMustMatchAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(
object value, ValidationContext validationContext)
{
var model = validationContext.ObjectInstance as Person;
if (model.Password == model.PasswordConfirm)
{
return ValidationResult.Success;
}
return new ValidationResult(
"Password and Password Confirmation must match",
new string[] { "Password", "PasswordConfirm" });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment