Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ibrahimsn98/phonenumberkit
Android Kotlin library to parse and format international phone numbers. Country code picker.
https://github.com/ibrahimsn98/phonenumberkit
android country-codes kotlin library lilphonenumber mask number phone phone-mask phone-number phonenumberkit picker
Last synced: about 1 month ago
JSON representation
Android Kotlin library to parse and format international phone numbers. Country code picker.
- Host: GitHub
- URL: https://github.com/ibrahimsn98/phonenumberkit
- Owner: ibrahimsn98
- License: apache-2.0
- Created: 2020-08-30T19:00:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-06T07:08:01.000Z (over 1 year ago)
- Last Synced: 2024-12-09T02:50:54.012Z (about 1 month ago)
- Topics: android, country-codes, kotlin, library, lilphonenumber, mask, number, phone, phone-mask, phone-number, phonenumberkit, picker
- Language: Kotlin
- Homepage:
- Size: 1.26 MB
- Stars: 159
- Watchers: 3
- Forks: 41
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PhoneNumberKit
Android **Kotlin** library to parse and format international phone numbers. Based on Google's libphonenumber library.[![](https://jitpack.io/v/ibrahimsn98/PhoneNumberKit.svg)](https://jitpack.io/#ibrahimsn98/PhoneNumberKit)
## Features
| |Features |
--------------------------|------------------------------------------------------------
:phone: | Validate, normalize and extract the elements of any phone number string.
:dart: | Convert raw phone number to formatted phone number string.
:mag: | Automatically detects country flag of the phone number.
:bookmark: | Country code selection bottom sheet.
:pushpin: | Convert country codes to country names and vice versa.
:tr: | 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.
```kotlin
val phoneNumberKit = PhoneNumberKit.Builder(this)
.setIconEnabled(true)
.admitCountries(listOf("tr", "ca", "de")) // List only those county formats
.excludeCountries(listOf("tr", "ca")) // Exclude those county formats
.build()phoneNumberKit.attachToInput(textField, "tr")
// OR
phoneNumberKit.attachToInput(textField, 1)
```To setup with country code selection bottom sheet
```kotlin
phoneNumberKit.setupCountryPicker(this) // Requires activity context
```To get an example phone number for given **iso2 code**
```kotlin
val exampleNumber = phoneNumberKit.getExampleNumber("tr")
```To parse raw text to phone number and receive country code, national number
```kotlin
val parsedNumber = phoneNumberKit.parsePhoneNumber(
number = "1266120000",
defaultRegion = "us"
)parsedNumber?.nationalNumber
parsedNumber?.countryCode
parsedNumber?.numberOfLeadingZeros
```To convert raw text to formatted phone number string
```kotlin
val formattedNumber = phoneNumberKit.formatPhoneNumber(
number = "1266120000",
defaultRegion = "us"
)
```To receive a country **flag icon** for given iso2 code
```kotlin
val flag = phoneNumberKit.getFlagIcon("ca")
```## Usage with Custom Item Layout
Add your custom item layout resource as a parameter
```kotlin
phoneNumberKit.setupCountryPicker(this, R.layout.my_item_layout, searchEnabled = true)
```You need to use below view ids in your layout file
```xml
```
## Demo
Country Code Picker
Format Example
Format Example
## Installation
> Follow me on Twitter [@ibrahimsn98](https://twitter.com/ibrahimsn98)
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:2.0.6'
}
```## Checklist
- [x] Search for country codes
- [x] Custom list item layout support
- [x] Better performance with coroutines
- [ ] Phone number validation indicator
- [x] Dark theme
- [ ] Tests## Conception
- This library is based on Google's lilPhoneNumber library (https://github.com/google/libphonenumber)
- Inspired from PhoneNumberKit Swift library by [marmelloy](https://github.com/marmelroy) (https://github.com/marmelroy/PhoneNumberKit)
- Flag images from [region-flags](https://github.com/behdad/region-flags)## License
PhoneNumberKit is available under the Apache license. See the [LICENSE](https://github.com/ibrahimsn98/PhoneNumberKit/blob/master/LICENSE) file for more info.