title: UItextfield with Input format
body: <p>I have 2 question</p>
  
  <p><strong>1) If textfield enter 10 digit , after just hitting 10th digit it call a function (myFunction), i have below code to fix length 10 digit,below code work when i press 11th digit.</strong> </p>
  
  <pre><code>#define MAX_LENGTH 10
  
  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
  
      if (textField.text.length &gt;= MAX_LENGTH &amp;&amp; range.length == 0)
      {
        [self myFunction];//not working it works when 11th time key is press
          return NO; // return NO to not change text
      }
    return YES;
  
  }
  
  
  -(void) myFunction
  {
  // do my stuff here 
  }
  </code></pre>
  
  <p><strong>2) My second question is regarding Credit card input format with multiple textfield.
  i have 3 textfield in which i have to enter 4 digit each, below is my code working fine, but it also work on press 5th times(like change textfield box )</strong></p>
  
  <p><a href="https://i.stack.imgur.com/Cv3p6.png" rel="nofollow"><img src="https://i.stack.imgur.com/Cv3p6.png" alt="enter image description here"></a></p>
  
  <p>in viewDidLoad</p>
  
  <pre><code>self.txt_box1.tag=1;
  self.txt_box2.tag=2;
  self.txt_box3.tag=3;
  
  
  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
       if ((textField.text.length &gt;= 4) &amp;&amp; (string.length &gt; 0))
      {
  
          NSInteger nextTag = textField.tag + 1;
          // Try to find next responder
          UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
          if (! nextResponder)
          {
              [nextResponder resignFirstResponder];
              [self myFunction];
          }
  
          if (nextResponder)
              // Found next responder, so set it.
              [nextResponder becomeFirstResponder];
  
          return NO;
      }
      return YES;
  }
  </code></pre>