Git Product home page Git Product logo

shsphonecomponent's Introduction

SHSPhoneComponent

UITextField and NSFormatter subclasses for formatting phone numbers. Allow different formats for different countries(patterns). Caret positioning works excellent.

How To Install

Use any of next methods:

  • use embedded framework /SHSPhoneComponents/SHSPhoneComponent.xcodeproj (iOS 8+)
  • pod 'SHSPhoneComponent'
  • copy /SHSPhoneComponents/Library folder to your project.

And import "SHSPhoneLibrary.h" on your Controller.

##Example Usage If you need complete example please see 'Example_iOS7+' or 'Example_iOS8+embedded' folders.

###Default Format

[self.phoneField.formatter setDefaultOutputPattern:@"+# (###) ###-##-##"];

shspc example 1

All input strings will be parsed in that way. Example: +7 (920) 123-45-67

###Prefix Format You can set prefix on all inputs:

[self.phoneField.formatter setDefaultOutputPattern:@"(###) ###-##-##"];
self.phoneField.formatter.prefix = @"+7 ";

shspc example 1

###Multiple Formats

[self.phoneField.formatter setDefaultOutputPattern:@"##########" imagePath:nil];
[self.phoneField.formatter addOutputPattern:@"+# (###) ###-##-##" forRegExp:@"^7[0-689]\\d*$" imagePath:@"flagRU"];
[self.phoneField.formatter addOutputPattern:@"+### (##) ###-###" forRegExp:@"^374\\d*$" imagePath:@"flagAM"];

shspc example 2

###Multiple Formats with prefix

[self.phoneField.formatter setDefaultOutputPattern:@"### ### ###"];
self.phoneField.formatter.prefix = @"+7 ";
[self.phoneField.formatter addOutputPattern:@"(###) ###-##-##" forRegExp:@"^1\\d*$" imagePath:@"SHSPhoneImage.bundle/flag_ru"];
[self.phoneField.formatter addOutputPattern:@"(###) ###-###" forRegExp:@"^2\\d*$" imagePath:@"SHSPhoneImage.bundle/flag_ua"];

###Specific Formats If you want to format some numbers in specific way just do

[self.phoneField.formatter addOutputPattern:@"+# (###) ###-##-##" forRegExp:@"^7[0-689]\\d*$" imagePath:@"flagRU"];
[self.phoneField.formatter addOutputPattern:@"+### (##) ###-###" forRegExp:@"^374\\d*$" imagePath:@"flagAM"];

##Formatting If you need only formatting function you can use SHSPhoneNumberFormatter class. For additional class info see http://serheo.github.io/SHSPhoneComponent/

##Requirements ARC Enabled. iOS 7+

##License SHSPhoneComponent is available under the MIT license. See the LICENSE file for more info.

shsphonecomponent's People

Contributors

jamesperlman avatar lfarah avatar serheo avatar

Watchers

 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.