title: Add hyphen automatically in text field but not able to edit the textfield (Phone number masking)
body: <p>Using the below code, I am able to add hyphen automatically, but not able to do editing in the textfield properly. </p>
  
  <p>For example when I click to insert any number between the already entered numbers in the textfield, this will insert the number at the end of the textfield and further not delete that number properly. Can anyone help me out?</p>
  
  <pre><code>-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {    
       if(textField == txtUserName)
       {
           if (range.location == 12)
           {
               return NO;
           }
           if (range.length == 0 &amp;&amp; ![[NSCharacterSet decimalDigitCharacterSet]   characterIsMember:[string characterAtIndex:0]])
           {
               return NO;
           }       
          if (range.length == 0 &amp;&amp; (range.location == 3 || range.location == 7))
           {
               txtUserName.text = [NSString stringWithFormat:@"%@-  %@",txtUserName.text,string];
               return NO;
           }
           if (range.length == 1 &amp;&amp;(range.location==4 ||range.location ==7))      
           {
               range.location--;
               range.length = 2;
                txtUserName.text = [txtUserName.text  stringByReplacingCharactersInRange:range withString:@""];
               NSLog(@"Nisha..%@",txtUserName.text);
               return NO;
            }
      }   
      return YES;
  }
  </code></pre>