Skip to content

bobbyzamora/SHSPhoneComponent

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SHSPhoneComponent

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

How To Install

pod 'SHSPhoneComponent' or copy /SHSPhoneComponent folder to your project.

##Example Usage If you need complete example please see /example folder.

###Default Format

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

shspc example 1

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

Also you can preset first part of number with format. For example, if you want numbers only from Russia, use next code:

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

shspc example 1

###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"];

shspc example 2

##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. Tested under iOS >= 5.0. iOS 7 beta support.

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

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors