title: Web API single string parameter validation using validation attributes
body: <p>I know that you can use Validation attributes on a model to validate it like so:</p>
  
  <pre><code>public class CommunicationQuery
  {
      [RegularExpression("[0-9]{0,10}", ErrorMessage = "Please enter a valid policy number")]
      public string PolicyId { get; set; }
      [RegularExpression("[0-9]{0,10}", ErrorMessage = "Please enter a valid member number")]
      public string MemberId { get; set; }
  }
  
  public IEnumerable&lt;Communication&gt; Get([FromUri]CommunicationQuery documentQuery)
  {
  
  }
  </code></pre>
  
  <p>But is it possible to validate a single string using validation attributes such as this?</p>
  
  <pre><code>public async Task&lt;HttpResponseMessage&gt; Get([RegularExpression("[0-9]{0,10}")]string id)
  {
  
  }
  </code></pre>
  
  <p>This didn't seem to work. The only ways I've been able to do this was to either create a wrapper object and use <code>[FromUri]</code>, use a custom <code>ActionFilterAttribute</code> on the action itself or to manually validate the parameter in the controller action using a regular expression.</p>