Code Monkey home page Code Monkey logo

stphoneformatter's Introduction

STPhoneFormatter

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.

stphoneformatter's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.