title: Set max length of UITextField AND convert to uppercase?
body: <p>I have a <code>Client Details</code> screen with many <code>UITextField</code>. I need to limit the <code>postcodeField</code> to a maximum of 7 characters and convert to uppercase automatically. I already have code to convert the text to uppercase, but it seems I cannot do anything else with that particular <code>UITextField</code> in its <code>Delegate</code>method</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  </code></pre>
  
  <p>Here is what I have tried:</p>
  
  <pre><code>#define MAXLENGTH 7
  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
      if (textField == self.postcodeField) {
          self.postcodeField.text = [textField.text stringByReplacingCharactersInRange:range withString:[string uppercaseString]];
          return NO;
      }
      if (self.postcodeField.text.length &gt;= MAXLENGTH &amp;&amp; range.length == 0)
      {
          return NO;
      }
      return YES;
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
      if (textField == self.postcodeField) {
          self.postcodeField.text = [textField.text stringByReplacingCharactersInRange:range withString:[string uppercaseString]];
          return NO;
      }
  
      NSUInteger newLength = [textField.text length] + [string length] - range.length;
      return (newLength &gt; 7) ? NO : YES;
  }
  </code></pre>
  
  <p>This code does not work. I know there are many threads with various solutions to setting a maximum length, but I can't find a solution that caters for uppercase conversion too. I am quite new to iOS so I apologise if this is seen as a duplicate post. Any help is much appreciated!</p>