title: How to limit the characters of textfield in iOS application up to 5 characters?
body: <p>I would like to limit the characters in <code>textField</code> of IOS Application. I tried all the methods given in Stack Overflow, so I am asking this question. </p>
  
  <p>Here I used one Label (secure code) and one textfield (5 characters).</p>
  
  <p>I had given the below code in <code>viewcontroller.m</code> file, but not working.</p>
  
  <pre><code>   myTextField.delegate = self
  
  -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  
  {
     NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  
     return !([newString length] &gt; 5);
  }
  </code></pre>