title: Uppercase attribute that converts the input to uppercase
body: <p>I am working in MVC4 and want to define a model using an <code>Uppercase</code> attribute. The idea would be that the presence of the Uppercase attribute would cause the model value to be converted to uppercase when it arrived at the server.</p>
  
  <p>At the moment I have the following code within the model:</p>
  
  <pre><code>    [Required]
      [Display(Name="Account Code")]
      [StringValidation(RegExValidation.AccountCode, Uppercase=true)]
      public string Account
      {
          get { return _account; }
          set
          {
              if (value != null)
                  _account = value.ToUpper();
          }
      }
  </code></pre>
  
  <p>But what I would really like is this:</p>
  
  <pre><code>    [Required]
      [Display(Name="Account Code")]
      [StringValidation(RegExValidation.AccountCode)]
      [Uppercase]
      public string Account { get; set; }
  </code></pre>
  
  <p>I think that I may need to create the Uppercase attribute as a <code>ValidationAttribute</code> to ensure it gets fired when the model hits the server. But that seems a bit wrong, as I'm not really validating the data. Is there a better way?</p>
  
  <p>Also, is there any way to ensure the invocation order on the attributes? I really want to convert the data to uppercase before the custom <code>StringValidation</code> attribute fires, as this checks the case of the text in the regex pattern.</p>
  
  <p>To add a bit of background to this, I want to reduce the need to add code to uppercase the data. The nirvana would be a single attribute, which updates the data on the way into the server, either in the model binding or validation stage. This attribute can then be referenced in the <code>StringValidation</code> attribute to amend the RegEx value used in its checks. I can also then lookup this attribute in a custom <code>TextBoxFor</code> helper method, such that I can add <code>text-transform: uppercase</code> so it looks correct on the client side.</p>
  
  <p>Does anyone have any ideas out there?</p>