title: Limiting UITextField to 2 digits representing a month
body: <p>I've created a view controller that allows a person to enter their credit card information to continue with a purchase. All is good except the pesky year &amp; month formatting. More specifically the month, where it's required the user only be able to input 2 digits (which was easy to do with the 'shouldChangeCharactersInRange' method) plus some sort of check that limits what kind of numbers can be left in the UITextField. Currently, the user can type any 2 digits inside (looks like this inside the text field: 83 or 21 etc.) but I need only digits from 1-12 being allowed.</p>
  
  <p>While looking around stack overflow I was sure someone has done something like this but I haven't been able to find anything. Can someone point me in the right direction please?</p>
  
  <p>What would be placed inside?</p>
  
  <pre><code>-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
      switch (textField.tag)
      {
          case 3: //Month.
              //This allows to tap on a UITextField, even if it already contains 2 digits, and deleting these digits with the delete key with out being thrown out because of 'resignFirstResponder'.
              if (textField.text.length &gt; 1 &amp;&amp; !([string length] == 0 &amp;&amp; range.length &gt; 0))
              {
                  [_textfieldMonth resignFirstResponder];
              }
  
  
              //End up with UITextField displaying only from 01 - 12.
  
  
              break;
  
          case 4: //Year.
              break;
      }
  }
  </code></pre>