title: How do I make an alternative required field in MVC 4 application?
body: <p>I have a <code>Model</code> which have both phone number and email in <code>MVC 4</code>. It's something like registration. So user can provide either email or cellphone number or both of them. However I can't make a alternative required field of them. 
  My Model is like </p>
  
  <pre><code>public class RegisterModel
      {
          [Required]
          [Display(Name = "User name")]        
          [UsernameValidator(ErrorMessage = "Only Letters and numbers")]
          [System.Web.Mvc.Remote("IsUserExitst", "Account", HttpMethod = "POST", ErrorMessage = "This user name already exists. Try a new one.")]
          public string UserName { get; set; }
  
          [Required]
          [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [DataType(DataType.Password)]
          [Display(Name = "Password")]
          public string Password { get; set; }
  
          [DataType(DataType.Password)]
          [Display(Name = "Confirm password")]
          [System.ComponentModel.DataAnnotations.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
          public string ConfirmPassword { get; set; }
  
          [Required]
          [MaxLength(50)]
          [EmailOrPhoneValidator(ErrorMessage = "Invalid Phone number")]
          [Display(Name = "Phone number")]
          [System.Web.Mvc.Remote("IsMobOrEmailExists", "Account", HttpMethod = "POST", ErrorMessage = "This Phone number or Email already exists. Try a new one.")]
          public string MobileNo { get; set; }
  
  
          [Required]
          [MaxLength(50)]
          [EmailAddress(ErrorMessage = "Invalid Email address")]
          [Display(Name = "Email")]
          [System.Web.Mvc.Remote("IsEmailExists", "Account", HttpMethod = "POST", ErrorMessage = "This Email already exists. Try a new one.")]
          public string Email { get; set; }
      }
  </code></pre>
  
  <p>Here I want to use <code>Email</code> and <code>PhoneNo</code> alternatively. I want to write a class which works as Custom required field. I have gone through this Questions, </p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/8906228/how-to-validate-one-field-related-to-anothers-value-in-asp-net-mvc-3">Question</a> Here the answer provided a solution combined with javascript. But I won't use it. I will write down the class file and implement my logics here.</li>
  <li><code>RequiredIf</code> is seems the exact suggestion of my question, but I so tired to try that solution. I am not capable to understand how to import the .dll in my project. and it's developed in Mvc 3</li>
  <li>Another <a href="https://stackoverflow.com/questions/2712511/data-annotations-for-validation-at-least-one-required-field?noredirect=1&amp;lq=1">solution</a>, but here they have combined the alternative properties in a class. So how do I do as my properties are completely separate. So what to do.   </li>
  </ol>