title: ASP.NET WebAPI 2: handle empty string query parameters
body: <p>We have an api used to get data of products:</p>
  
  <pre><code>public IHttpActionResult GetProducts(ProductFilter productFilter)
  {
      try
      {
          .....
      }
      catch(Exception)
      {
          throw new OurCustomException();
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>public class ProductFilter
  {
      [RegularExpression(@"^[a-zA-Z0-9]{11}$")]
      public String Number { get; set; }
      .....
  }
  </code></pre>
  
  <p>Here is what i want:</p>
  
  <ol>
  <li><p>When send <code>GET /api/products?number=Test1234567</code> it will return information of a product with the number "Test1234567"</p></li>
  <li><p>When send <code>GET /api/products?number=</code> it will return error because the empty string does not match the regex</p></li>
  <li><p>When send <code>GET /api/products</code> it will return information of all products</p></li>
  </ol>
  
  <p>So can you suggest me any way to do this by using just Validation Attribute, since we have a common method to handle <code>ValidationException</code> and we cannot throw <code>ValidationException</code> from method <code>GetProducts</code>. I have tried to use <code>[Required]</code> and <code>[DisplayFormat(ConvertEmptyStringToNull = false)]</code> on <code>Number</code> but none of them worked.</p>
  
  <p>And please also inform me if it is impossible.</p>