Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serheo/shsphonecomponent
UITextField and NSFormatter subclasses for formatting phone numbers. Allow different formats for different countries(patterns).
https://github.com/serheo/shsphonecomponent
formatter ios nsformatter-subclasses objective-c phone phone-format phone-formatter uitextfield
Last synced: about 19 hours ago
JSON representation
UITextField and NSFormatter subclasses for formatting phone numbers. Allow different formats for different countries(patterns).
- Host: GitHub
- URL: https://github.com/serheo/shsphonecomponent
- Owner: Serheo
- License: mit
- Created: 2013-05-02T19:58:29.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2018-12-24T03:30:46.000Z (almost 6 years ago)
- Last Synced: 2024-12-22T14:07:27.376Z (about 19 hours ago)
- Topics: formatter, ios, nsformatter-subclasses, objective-c, phone, phone-format, phone-formatter, uitextfield
- Language: Objective-C
- Size: 427 KB
- Stars: 371
- Watchers: 17
- Forks: 55
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SHSPhoneComponent
=================UITextField and NSFormatter subclasses for formatting phone numbers. Allow different formats for different countries(patterns).
Caret positioning works excellent.Swift version is here - https://github.com/Serheo/PhoneNumberFormatter
## 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
``` objective-c
[self.phoneField.formatter setDefaultOutputPattern:@"+# (###) ###-##-##"];
```
All input strings will be parsed in that way.
Example: +7 (920) 123-45-67### Prefix Format
You can set prefix on all inputs:
``` objective-c
[self.phoneField.formatter setDefaultOutputPattern:@"(###) ###-##-##"];
self.phoneField.formatter.prefix = @"+7 ";
```
### Multiple Formats
``` objective-c
[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"];
```
### Multiple Formats with prefix
``` objective-c
[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
``` objective-c
[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/## Issues and Solutions
if you are using any predictions/suggestion in the textfield, set hasPredictiveInput flag to YES.## Requirements
ARC Enabled.
iOS 7+## License
SHSPhoneComponent is available under the MIT license. See the LICENSE file for more info.