title: Fluent Validation Conditional Rules
body: <p>We have a conditional requirement that not empty rule should be applied to a field only when there is a flag turned on. Something like the code below. </p>
  
  <p>Is this a correct approach?</p>
  
  <pre><code>public AccountSetupModelValidator(ISessionProvider sessionProvider)
      {
          var regexPatterns = new RegExPatterns();
  
          RuleFor(x =&gt; x.MemorableDate)
              .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_1001_memorabledate);
  
  
          RuleFor(x =&gt; x.MemorableDateAnswer)
              .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_1001_memorabledateanswer)
              .Matches(regexPatterns.MemorableDateFormat).WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100007_memorabledateinvalidformat)
              .Length(5).WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100006_maxlength);
  
         RuleFor(x =&gt; x.SecurityQuestion)
             .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_1001_securityquestion);
  
          RuleFor(x =&gt; x.SecurityAnswer)
              .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_1001_securityanswer) 
              .Length(1, 40).WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100006_maxlength);
  
          if (sessionProvider.OnboardingApplicationData.ToggleNavigationView.HasProvisionalAccount)
          {
  
                RuleFor(x =&gt; x.TempCardNumber)
                  .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_100006_tempcard)
                  .Matches(regexPatterns.NumericOnly)
                  .WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100007_numbersonly)
                  .Length(15).WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_100006_tempcard);
  
              RuleFor(x =&gt; x.SecurityCode)
                  .NotEmpty().WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_100006_tempcard)
                  .Matches(regexPatterns.NumericOnly)
                  .WithLocalizedMessage(ResourceAreas.Messages.Message_Onboarding_100007_numbersonly)
                  .Length(4).WithLocalizedMessage(ResourceAreas.Messages.Message_AccountSetup_100006_securitycode);
          }
  
      }
  </code></pre>