GithubHelp home page GithubHelp logo

jndisrupter / jnphonenumberview Goto Github PK

View Code? Open in Web Editor NEW
8.0 5.0 4.0 19.12 MB

Phone Number Validation with country dial code picker

License: MIT License

Swift 98.64% Ruby 1.26% C 0.10%
phone-number country-codes country-list country-picker country-flags swift library phonenumber-validation country libphonenumber

jnphonenumberview's Introduction

JNPhoneNumberView

CI Status Version License Platform

Requirements

  • iOS 9.0+ / macOS 10.10+
  • Xcode 9.0+
  • Swift 4+

Installation

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

pod 'JNPhoneNumberView'

Example

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

JNPhoneNumberView

used to to show the country dial code and the phone number, you can click on the dial code and select another country from the countries picker, this view has a delegate methods to pass the international number and validity of it.

Screenshots

Usage

  • To add JNPhoneNumberView in interface builder:

    1. Drag an UIView and change the class to "JNPhoneNumberView"

    2. Add refrence for it in the view controller.

  • Implement JNPhoneNumberViewDelegate:

    Set the 'delegate' in your view controller and implement the following methods:

    • Presenter View Controller to be used for presenting the Country list picker:

      func phoneNumberView(getPresenterViewControllerFor phoneNumberView: JNPhoneNumberView) -> UIViewController
    • Get Country picker configuration:

      func phoneNumberView(getCountryPickerAttributesFor phoneNumberView: JNPhoneNumberView) -> JNCountryPickerConfiguration
    • Did change text with new national phone number and selected country:

      func phoneNumberView(didChangeText nationalNumber: String, country: JNCountry, forPhoneNumberView phoneNumberView: JNPhoneNumberView)
    • Did end editing with bool value indicate if the phone number is valid, new national phone number and selected country:

      func phoneNumberView(didEndEditing nationalNumber: String, country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView)
    • Selected Country did changed with bool value indicate if the phone number is valid:

      func phoneNumberView(countryDidChanged country: JNCountry, isValidPhoneNumber: Bool, forPhoneNumberView phoneNumberView: JNPhoneNumberView)
  • Implement JNPhoneNumberViewDataSourceDelegate:

    Set dataSourceDelegate in your view controller if you want to provide a source with custom countries instead of using the our like the following:

    func countryPickerViewControllerLoadCountryList(_ phoneNumberView: JNPhoneNumberView, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
  • View Customization:

    We provide appearance customization using JNPhoneNumberViewConfiguration that has the following attributtes:

    • countryDialCodeTitleColor Color for country dial code.
    • countryDialCodeTitleFont: Font for country dial code.
    • phoneNumberTitleColor: Color for phone number textfield.
    • phoneNumberTitleFont: Font for phone number textfield.
    • phoneNumberPlaceHolder: Place hodler for phone number textfield.
    • leftToolBarBarButtonItemTitle: Title for Tool BarBar ButtonItem that appear of Keyboard.
    • maximumNumbrOfDigits: Maximum number of digits allowed to add. the defualt value is 30 digit

Public Methods:

  1. Set a default country using this method, you just have to pass a country code such as "US", "PS":

    func setDefaultCountryCode(defaultCountryCode: String) 
  2. Set View configuration to customization view appearance:

    func setViewConfiguration(_ configuration: JNPhoneNumberViewConfiguration) 
  3. Set phone number in JNPhoneNumberView:

    func setPhoneNumber(phoneNumber: String)
  4. Set phone number from national number and country:

    func setPhoneNumber(nationalNumber: String, preferredRegionCode: String)
  5. Get phone number from JNPhoneNumberView:

    func getPhoneNumber() -> String 
  6. Is phone number valid:

    func isValidPhoneNumber() -> Bool
  7. Get National Phone Number:

    func getNationalPhoneNumber() -> String
  8. Get dial code:

    func getDialCode() -> String

Public Properties:

  1. delegate : Picker Delegate
  2. dataSourceDelegate: Data Source Delegate

JNCountryPickerViewController

used to to show the countries list and select one of the countries, this view controller has a delegate methods to pass the selected country as JNCountry, also we provide the developer the flexiability to pass a custom country list insead of use the cached one.

Screenshots

Usage

To present JNCountryPickerViewController programmatically:

  1. Initiate JNCountryPickerViewController.

      let countryPickerViewController = JNCountryPickerViewController()
  2. Emped the view controller in navigation controller.

      let nevigationController = UINavigationController(rootViewController: countryPickerViewController)
  3. Present the navigation controller modally.

      self.present(nevigationController, animated: true, completion: nil)
  • Implement JNCountryPickerViewControllerDelegate:

    Set the 'delegate' in your view controller and implement the following methods:

    • Did select Country
    func countryPickerViewController(_ controller: JNCountryPickerViewController, didSelectCountry country: JNCountry)
  • Implement JNPhoneNumberViewDataSourceDelegate:

    Set the 'dataSourceDelegate' in your view controller and implement the following methods:

    • Load country list from custom source
    func countryPickerViewControllerLoadCountryList(_ controller: JNCountryPickerViewController, completion: @escaping ([JNCountry]) -> Void, errorCompletion: @escaping (NSError) -> Void)
  • View Customization:

    We provide appearance customization using JNCountryPickerConfiguration that has the following attributtes:

    • selectedTitleFont Selected item title font.
    • titleFont Not selected item title font.
    • selectedTitleColor Selected item title color.
    • titleColor Not selected item title color.
    • emptySearchMessageFont Message for empty search result.
    • emptySearchMessageColor Color for empty search result message.
    • searchBarTintColor Search bar tint color.
    • navigationBarColor Navigation bar color.
    • naigationBarTintColor Navigation bar tint color.
    • navigationBarTitle Navigation bar Title.
    • navigationBarTitleTextAttributes Navigation bar title text attributtes.
    • selectBarButtonTitle Select bar button title.
    • loadingAcivityIndicatorColor Loading acivity indicator color.
    • emptySearchMessage Message for empty search result.
    • emptySearchImage Image for empty search result.
    • viewBackgroundColor View controller background color.
    • pickerLanguage Picker language.
    • tableCellInsets Cell margins.
    • tableCellCornerRaduis Cell corner raduis.
    • tableCellBackgroundColor Cell background color.
    • showDialCode Show country dial code to appear after country name.

Public Properties:

  1. pickerConfiguration: you can set a custom configuration instead of the default configuration as described in view customization section.
  2. selectedCountry: you can set country to be selected when picker opened.
  3. delegate : Picker Delegate
  4. dataSourceDelegate: Data Source Delegate

Notes

  1. Custom country entitiy must conform to JNCountry protocol that has the following:

    • code Country code.
    • name Country name.
    • dialCode Country dial code.

    The Country Data should Follow ISO 3166-1

Author

Hamzeh Khanfar & Jayel Zaghmoutt

License

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

jnphonenumberview's People

Contributors

hamzakhanfar avatar jayelzaghmoutt avatar yara-abuhijleh1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jnphonenumberview's Issues

Using in UITableView, delegate not set properly, help me how to set in TableViewCell textfield items in swift 5

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

JNPhoneNumberView.xib issue

The country code screen opens when we click on the right side of the view.

To Reproduce
Steps to reproduce the behavior:

  1. Continuously tap on the right side of the JNPhoneNumberView.xib by changing the position of the tap a little bit.
  2. suddenly the country code screen will present.

Expected behavior
This should be done only when we click on the left side of the view.

Screenshots

Here is the problem. The constraint constant should be .zero instead of 10.

Screenshot 2023-12-20 at 2 44 06 PM

Smartphone (please complete the following information):
All devices.

-Mayur

How to differentiate two phone number views in the delegate methods?

I have two phone numbers of views in my app. I want to differentiate which phone number view is user typing in the delegate methods like below text field delegate methods

    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        if(textField == firsttextfield)
        {
            return true
        }
        
        return true
    }

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.