title: How to limit characters in UITextField
body: <p>I have a <code>UITextField</code> with the following restrictions - characters can only be numbers, as in the method below.  I want to also limit the number of max characters to 3 digits.  How can I modify my method to do that?</p>
  
  <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  NSCharacterSet *aCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
  for (int i = 0; i &lt; [string length]; i++) {
      unichar aCharacter = [string characterAtIndex:i];
      if ([aCharacterSet characterIsMember:aCharacter]) {
          return YES;
      }
  }
  
  NSUInteger newLength = self.textField.text.length + string.length - range.length;
  return (newLength &gt; 3) ? NO : YES;
  }
  </code></pre>