Skip to content

Brsoyan/HBPhoneNumberFormatter

Repository files navigation

HBPhoneNumberFormatter

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

  • #import <HBPhoneNumberFormatter/HBPhoneNumberFormatter.h>

You can set your custom formatting like @"(123) 1234:123" or @"123-123-12:12"

[[HBPhoneNumberFormatter alloc] initWithFormatting:@"(111) 1111-111"]

If you need prefix for your textField use this HBPhoneNumberFormatter method.

- (void)setCountryName:(NSString *)name textField:(UITextField *)textField;

All coutry name you can see in this class HBCountryCode

  • In your ViewController conform to protocol UITextFieldDelegate. Override this method
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    //check textField
    if ([textField isEqual:self.phoneField]) {
    	HBPhoneNumberFormatter *formatter = [[HBPhoneNumberFormatter alloc] initWithFormatting:@"(111) 1111-111"];
        return [formatter textField:textField shouldChangeCharactersInRange:range replacementString:string];
    }
    return YES;
}
  • If you need change or disable animation. HBPhoneNumberFormatter object have this properties you set your animation size and duration.
	isShake, (default == YES)
	shakeSize, (default == 5)
	shakeDuration, (default == 0.1)
	shakeRepeatCount, (default == 2)

Example`

HBPhoneNumberFormatter *formatter = [[HBPhoneNumberFormatter alloc] initWithFormatting:@"(111) 1111-111"];
formatter.shakeSize = 10;
formatter.shakeRepeatCount = 4; 

PhoneNumberTextField automatically formats phone numbers and gives the user full editing capabilities. alt text

You can check your textField validation - (BOOL)numberIsValidPhoneText:(NSString *)phoneText;

Installation

HBPhoneNumberFormatter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'HBPhoneNumberFormatter', '~> 1.6'

Author

HaykBrsoyan, haykbrsoyan@gmail.com

License

HBPhoneNumberFormatter is available under the MIT license. See the LICENSE file for more info.

HBPhoneNumberFormatter