Hello again, the second question I wanted to ask is: How can I remove some characters from TextField by clicking on Button. those. Suppose I have a text (phone number) - +7 (123) 456-78-90, after pressing the characters are deleted - @ "+ () -", it turns out: 71234567890. Do I use textDidChange? Tell me?)

  • Very very necessary, I searched all of Google, I can not find it anywhere. - SuperPonchik
  • 2
    What is the actual problem? Run your code when you press a button? Get text from TextField as string? Filter characters in a string? Write back changed text in TextField ? - VladD
  • Yes, we all do not write ready-made answers here, lurking in anticipation of what is incomprehensible. - Stanislav Pankevich

1 answer 1

 NSString* phoneNumber = [self.phoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""]; phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"+" withString:@""]; phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"(" withString:@""]; phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@")" withString:@""]; phoneNumber = [phoneNumber stringByReplacingOccurrencesOfString:@"-" withString:@""]; 

like that

  • Doesn't work: C, did everything right - SuperPonchik
  • Only if without NSString, directly .. - SuperPonchik