title: Custom Validation in MVC - Match New Email To Confirmed Email
body: <p>I am trying to create a new custom validation in which I can compare two values within the same class. in this case its checking that when people change their email they have to enter it twice and those two values match. (Would do the same for adding/changing passwords)</p>
  
  <pre><code>    public class CompareAttribute : ValidationAttribute
      {
          public string CompareValue { get; set; }
  
          public override bool IsValid(string value)
        {
          //we not validating if its required or not!
          if (value == null)
              return true;
  
  
  
          return value.ToLower().Equals(CompareValue.ToLower());
         }
       }
  </code></pre>
  
  <p>This is my validationattribute class above.
  I have then tried to use it from within my class doing this</p>
  
  <pre><code>[Compare(CompareValue = newEmail, ErrorMessage = "New email and Confirm email do not match")]
  </code></pre>
  
  <p>but i get a error on newEmail</p>
  
  <blockquote>
    <p>Error 3   An object reference is required for the non-static field, method, or property 'BensBoxing.Domain.EmailChange.newEmail.get'</p>
  </blockquote>
  
  <p>the whole of my class is this</p>
  
  <pre><code>public class EmailChange : Entity
  {
      [DisplayName("Current Email Address")]
      [DataType(DataType.Text)]
      [Required(ErrorMessage = "Current Email is a required field")]
      [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Valid Email Address is required.")]
      public virtual string currentEmail { get; set; }
  
      [DisplayName("New Email Address")]
      [DataType(DataType.Text)]
      [Required(ErrorMessage = "New Email is a required field")]
      [EmailInUse(ErrorMessage = "Email is currently in use")]
      [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Valid Email Address is required.")]
      public virtual string newEmail { get; set; }
  
      [DisplayName("Confirm Email Address")]
      [DataType(DataType.Text)]
      [Required(ErrorMessage = "Confirmed Email is a required field")]
      [Compare(CompareValue = newEmail, ErrorMessage = "New email and Confirm email do not match")]
      [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Valid Email Address is required.")]
      public virtual string confirmEmail { get; set; }
  
  }
  </code></pre>