Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used Matthews post above as a base.</p> <p>This will format as so: (444) 444-4444</p> <p>It also handles backspaces, unlike the answer above. </p> <pre><code>- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if(textField == _txtPhone1 || textField == _txtPhone2 || textField == _txtPhone3 || textField == _txtPhone4) { NSCharacterSet *numSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789-() "]; NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; int charCount = [newString length]; if ([newString rangeOfCharacterFromSet:[numSet invertedSet]].location != NSNotFound || [string rangeOfString:@")"].location != NSNotFound || [string rangeOfString:@"("].location != NSNotFound || [string rangeOfString:@"-"].location != NSNotFound || charCount &gt; 14) { return NO; } if (![string isEqualToString:@""]) { if (charCount == 1) { newString = [NSString stringWithFormat:@"(%@", newString]; } else if(charCount == 4) { newString = [newString stringByAppendingString:@") "]; } else if(charCount == 5) { newString = [NSString stringWithFormat:@"%@) %@", [newString substringToIndex:4], [newString substringFromIndex:4]]; } else if(charCount == 6) { newString = [NSString stringWithFormat:@"%@ %@", [newString substringToIndex:5], [newString substringFromIndex:5]]; } else if (charCount == 9) { newString = [newString stringByAppendingString:@"-"]; } else if(charCount == 10) { newString = [NSString stringWithFormat:@"%@-%@", [newString substringToIndex:9], [newString substringFromIndex:9]]; } } textField.text = newString; return NO; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload