title: Regex validation with fluent validation ASP.NET Core WebApi
body: <p>I'm working with WebApi project and have used fluent validation for validating the request. </p>
  
  <p>Userbase Dto.</p>
  
  <pre><code>public class UserBaseDto
  {    
      [JsonProperty("email")]
      public string Email { get; set; }
  
      [JsonProperty("countryId")]
      public int CountryId { get; set; }
  
      [JsonProperty("phoneNumber")]
      public string PhoneNumber { get; set; }
  }
  </code></pre>
  
  <p>UserRegister Dto.</p>
  
  <pre><code>public class RegisterDto : UserBaseDto
  {
  }
  </code></pre>
  
  <p>UserBaseDtoValidator.</p>
  
  <pre><code>public class UserBaseDtoValidator : AbstractValidator&lt;UserBaseDto&gt;
  {
      public UserBaseDtoValidator()
      {            
          RuleFor(x =&gt; x.Email)
              .EmailAddress()
              .WithMessage("Please provide valid email");
  
          RuleFor(x =&gt; x.PhoneNumber)
              .MatchPhoneNumberRule()
              .WithMessage("Please provide valid phone number");
      }
  }
  </code></pre>
  
  <p><code>MatchPhoneNumberRule</code> is a custom validator</p>
  
  <pre><code>public static class CustomValidators
  {
      public static IRuleBuilderOptions&lt;T, string&gt; MatchPhoneNumberRule&lt;T&gt;(this IRuleBuilder&lt;T, string&gt; ruleBuilder)
      {
          return ruleBuilder.SetValidator(new RegularExpressionValidator(@"((?:[0-9]\-?){6,14}[0-9]$)|((?:[0-9]\x20?){6,14}[0-9]$)"));
      }
  }
  </code></pre>
  
  <p>Regex is accepting 6 to 14 digit phone number.</p>
  
  <p>Here, I want to check validation for registration request. So, I have done something like:</p>
  
  <pre><code>public class RegisterDtoValidator : AbstractValidator&lt;RegisterDto&gt;
  {
      public RegisterDtoValidator()
      {
          RuleFor(x =&gt; x).SetValidator(new UserBaseDtoValidator());
      }       
  }
  </code></pre>
  
  <p>All other validations working fine. However, regex is working for lower limit but when I pass more than 14 digit, validation not getting triggered. </p>
  
  <p>Same expression working with <code>RegularExpressionAttribute</code> </p>