Latest 1.1.1
Homepage https://github.com/SebastienThiebaud/STPhoneFormatter
License MIT
Platforms ios 5.0, requires ARC
Authors

A custom formatter to deal with an international phone number inside a UITextField.

STPhoneFormatter screenshot

Documentation

You can install STPhoneFormatter from CocoaPods or manually. If you choose the most annoying method, please include these 3 files:

  • STPhoneFormatter.h
  • STPhoneFormatter.m
  • FormatsCountriesPhone.plist

Two different formats of phone number are available: the formatted one @property formattedPhoneNumber and the unformatted one - (NSString *)internationalPhoneNumber.

You can access to the country’s code and name with the @property countryCode and @property countryName.

Also, you can customize the format of the phone number by setting the country with the method - (BOOL)setCountryCode:(NSString *)countryCode;. The country’s code must respect the ISO 3166.

If you want to contribute by adding more country, please submit your own .plist by a pull request.

Demo

Build and run the project STPhoneFormatterExample in Xcode to see STPhoneFormatter in action.

Example Usage

The first thing to do is to set the delegate of your UITextField and in the delegate method (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string to add this:

BOOL phoneNumberHasChanged = [[STPhoneFormatter phoneFormatter] phoneNumberMustChangeInRange:range replacementString:string];

if (phoneNumberHasChanged) {
    textField.text = [[STPhoneFormatter phoneFormatter] formattedPhoneNumber];
}

return NO;

IMPORTANT: Don’t forget to return the value NO.

Contact

Sebastien Thiebaud

License

STPhoneFormatter is available under the MIT license.

Latest podspec

{
    "name": "STPhoneFormatter",
    "version": "1.1.1",
    "summary": "A custom formatter to deal with an international phone number inside a UITextField.",
    "homepage": "https://github.com/SebastienThiebaud/STPhoneFormatter",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Sebastien THIEBAUD": "[email protected]"
    },
    "source": {
        "git": "https://github.com/SebastienThiebaud/STPhoneFormatter.git",
        "tag": "v1.1.1"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source_files": "STPhoneFormatter/STPhoneFormatter.{h,m}",
    "resources": "STPhoneFormatter/FormatsCountriesPhone.plist",
    "requires_arc": true
}

Pin It on Pinterest

Share This