AKNSString+phoneFormatter.objc
Installation
Add this line to your application's Podfile:
pod 'AKNSString+phoneFormatter.obj'
And then execute:
$ pod install
Usage
-(NSString*)setFullPhoneFormat:(NSString*)phone;
NSString *phoneNumber = @"71111111111";
phoneNumber = [phoneNumber setFullPhoneFormat:phoneNumber];
Result:
+7 (111) 111-11-11
-(NSString*)resetFullPhoneFormat:(NSString*)phone;
NSString *phoneNumber = @"+7 (111) 111-11-11";
phoneNumber = [phoneNumber resetFullPhoneFormat:phoneNumber];
Result:
71111111111
Firstly you need to set phone prefix. In textField "textFieldShouldBeginEditing" or "textFieldDidBeginEditing" delegate methods call this:
- (void)textFieldDidBeginEditing:(UITextField *)textField{
textField.text = [textField.text phonePrefix];
}
And then in in textField "textFieldDidChange" delegate method:
-(void)textFieldDidChange :(UITextField *)textField{
textField.text = [textField.text phoneFormatFromString:textField.text];
}
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/it-machine/AKNSString-phoneFormatter.objc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.