title: Fluent validation custom validation rules
body: <p>I have model:</p>
  
  <pre><code>[Validator(typeof(RegisterValidator))]
  public class RegisterModel
  {
      public string Name { get; set; }
  
      public string Email { get; set; }
  
      public string Password { get; set; }
  
      public string ListOfCategoriess { get; set; }
  }
  </code></pre>
  
  <p>And validator for model:</p>
  
  <pre><code>public class RegisterValidator:AbstractValidator&lt;RegisterModel&gt;
  {
      public RegisterValidator(IUserService userService)
      {
          RuleFor(x =&gt; x.Name).NotEmpty().WithMessage("User name is required.");
          RuleFor(x =&gt; x.Email).NotEmpty().WithMessage("Email is required.");
          RuleFor(x =&gt; x.Email).EmailAddress().WithMessage("Invalid email format.");
          RuleFor(x =&gt; x.Password).NotEmpty().WithMessage("Password is required.");
          RuleFor(x =&gt; x.ConfirmPassword).NotEmpty().WithMessage("Please confirm your password.");
      }
  }
  </code></pre>
  
  <p>I have validator factory, that should resolve dependency:</p>
  
  <pre><code>public class WindsorValidatorFactory : ValidatorFactoryBase 
  {
      private readonly IKernel kernel;
  
      public WindsorValidatorFactory(IKernel kernel)
      {
          this.kernel = kernel;
      }
  
      public override IValidator CreateInstance(Type validatorType)
      {
          if (validatorType == null)
              throw new Exception("Validator type not found.");
          return (IValidator) kernel.Resolve(validatorType);
      }
  }
  </code></pre>
  
  <p>I have IUserService, that has methods <code>IsUsernameUnique(string name)</code> and IsEmailUnique(string email)` and want to use it in my validator class (model should be valid only if it have unique username and email).</p>
  
  <ol>
  <li>how to use my service for validation?</li>
  <li>is it possible to register multiple Regular Expression Rules with different error messages? will it work on client side? (if no, how to create custom validation logic for it?)</li>
  <li>is validation on server side will work automatically before model pass in action method, and it is enough to call ModelState.IsValid property, or I need to do something more?
  <strong>UPDATE</strong></li>
  <li>is it possible to access to all properties of model when validate some property? (for example I want to compare Password and ConfirmPassword when register)</li>
  </ol>