cefjoeii / PhoneNumberKit

Android Kotlin library to parse and format international phone numbers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PhoneNumberKit

Android Kotlin library to parse and format international phone numbers. Based on Google's libphonenumber library.

Features

Features
☎️ Validate, normalize and extract the elements of any phone number string.
🎯 Convert raw phone number to formatted phone number string.
πŸ” Automatically detects country flag of the phone number.
πŸ”– Country code selection bottom sheet.
πŸ“Œ Convert country codes to country names and vice versa.
πŸ‡ΉπŸ‡· Get country flag icon for given iso2 code.

Usage

Create a phoneNumberKit instance and attach it to an editTextLayout. That's all you have to do.

val phoneNumberKit = PhoneNumberKit(this) // Requires context

phoneNumberKit.attachToInput(textField, 1)

To setup with country code selection bottom sheet

phoneNumberKit.setupCountryPicker(this) // Requires activity

To get an example phone number for given iso2 code

val exampleNumber = phoneNumberKit.getExampleNumber("tr")

To parse raw text to phone number and receive country code, national number

val parsedNumber = phoneNumberKit.parsePhoneNumber(
    number = "1266120000",
    defaultRegion = "us"
)

parsedNumber?.nationalNumber
parsedNumber?.countryCode
parsedNumber?.numberOfLeadingZeros

To convert raw text to formatted phone number string

val formattedNumber = phoneNumberKit.formatPhoneNumber(
    number = "1266120000",
    defaultRegion = "us"
)

To receive a country flag icon for given iso2 code

val flag = phoneNumberKit.getFlagIcon("ca")

To receive country name or iso2 code from given country code

val country = phoneNumberKit.getCountry(90)

Demo

Country Code Picker Format Example Format Example

Installation

Step 1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.ibrahimsn98:PhoneNumberKit:1.1'
}

Checklist

  • Search for country codes
  • Custom list item layout support
  • Phone number validation indicator
  • Better performance with coroutines
  • Dark theme
  • Tests

Conception

License

PhoneNumberKit is available under the Apache license. See the LICENSE file for more info.

About

Android Kotlin library to parse and format international phone numbers.

License:Apache License 2.0


Languages

Language:Kotlin 100.0%