myanmar-phonenumber-kt
所属分类:Kotlin编程
开发工具:kotlin
文件大小:0KB
下载次数:0
上传日期:2021-09-16 14:34:50
上 传 者:
sh-1993
说明: no intro
(Port of myanmar-phonenumber(https://github.com/kaungmyatlwin/myanmar-phonenumber) written in Kotlin to check valid myanmar mobile numbers, get mobile operator s name, sanitize mobile numbers and get mobile network types.)
文件列表:
.idea/ (0, 2021-09-16)
.idea/.name (13, 2021-09-16)
.idea/codeStyles/ (0, 2021-09-16)
.idea/codeStyles/Project.xml (4499, 2021-09-16)
.idea/codeStyles/codeStyleConfig.xml (209, 2021-09-16)
.idea/misc.xml (332, 2021-09-16)
.idea/modules.xml (292, 2021-09-16)
.idea/myanmarphonenumberkt.iml (336, 2021-09-16)
.idea/runConfigurations.xml (564, 2021-09-16)
.idea/vcs.xml (180, 2021-09-16)
.travis.yml (387, 2021-09-16)
LICENSE.md (11354, 2021-09-16)
build.gradle (692, 2021-09-16)
buildSrc/ (0, 2021-09-16)
buildSrc/build.gradle.kts (116, 2021-09-16)
buildSrc/src/ (0, 2021-09-16)
buildSrc/src/main/ (0, 2021-09-16)
buildSrc/src/main/kotlin/ (0, 2021-09-16)
buildSrc/src/main/kotlin/Config.kt (943, 2021-09-16)
gradle.properties (892, 2021-09-16)
gradle/ (0, 2021-09-16)
gradle/wrapper/ (0, 2021-09-16)
gradle/wrapper/gradle-wrapper.jar (56177, 2021-09-16)
gradle/wrapper/gradle-wrapper.properties (232, 2021-09-16)
gradlew (5296, 2021-09-16)
gradlew.bat (2260, 2021-09-16)
settings.gradle (36, 2021-09-16)
src/ (0, 2021-09-16)
src/main/ (0, 2021-09-16)
src/main/kotlin/ (0, 2021-09-16)
src/main/kotlin/com/ (0, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/ (0, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/ (0, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/MyanmarPhoneNumberUtils.kt (1615, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/NetworkType.kt (339, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/Operator.kt (724, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/extract/ (0, 2021-09-16)
src/main/kotlin/com/aungkyawpaing/mmphonenumber/extract/MyanmarPhoneNumberExtractor.kt (662, 2021-09-16)
... ...
[ ![Download](https://api.bintray.com/packages/vincent-paing/maven/mmphonenumber/images/download.svg) ](https://bintray.com/vincent-paing/maven/mmphonenumber/_latestVersion)
[![Build Status](https://travis-ci.com/vincent-paing/myanmar-phonenumber-kt.svg?branch=master)](https://travis-ci.com/vincent-paing/myanmar-phonenumber-kt)
Kotlin port of [myanmar-phonenumber](https://github.com/kaungmyatlwin/myanmar-phonenumber) to check valid myanmar mobile numbers, get mobile operator's name, sanitize mobile numbers and get mobile network types.
### Features
#### Phone Number Normalization
An extensible normalizier allows you to normalize the phone number into a standardized format you want. The default out of the box provides
- Trimming whit spaces, dashes, and decimals
- Converting to English numbers
- Replacing and standardizing to 09
```kotlin
val input = "+"
val normalizer = MyanmarPhoneNumberNormalizer()
val result = normalizer.normalize(input)
print(result) //: 09784123456
```
##### Custom Rules
You can also use the builder provided to add custom rules. This allows you to create your own standardized format such as using "+959" instead of "09", or converting other languages to English numerals etc.
```kotlin
class NineFiveNineRule : Rule {
private val possibleCases = Regex("(09-)|(\\+959)|(09\\s)|(959)|(09\\.)")
override fun convert(input: String): String {
if (possibleCases.containsMatchIn(input)) {
return input.replaceFirst(possibleCases, "+959")
}
return input
}
}
val builder = MyanmarPhoneNumberNormalizer.Builder()
builder.addRule(NineFiveNineRule())
val input = "09784123456"
val output = builder.build().normalize(input)
print(output) //+959784123456
```
#### Phone number Validaiton
Check whether a phone number is a valid Myanmar phone number
```kotlin
MyanmarPhoneNumberUtils.isValidMyanmarPhoneNumber("09978412345") //true
MyanmarPhoneNumberUtils.isValidMyanmarPhoneNumber("14155552671") //false
```
#### Opreator Checking
Check which opreator the number is from
```kotlin
MyanmarPhoneNumberUtils.getTelecomOperator("09958412345") //Ooredoo
MyanmarPhoneNumberUtils.getTelecomOperator("09784123456") //Telenor
MyanmarPhoneNumberUtils.getTelecomOperator("09420012345") //MPT
MyanmarPhoneNumberUtils.getTelecomOperator("09690000966") //MyTel
```
#### Network Type Checking
Check which network the numer belongs to
```kotlin
MyanmarPhoneNumberUtils.getNetworkType("09978412345") //GSM
MyanmarPhoneNumberUtils.getNetworkType("09451212123") //WCDMA
MyanmarPhoneNumberUtils.getNetworkType("096355555") //CDMA 450Hz
MyanmarPhoneNumberUtils.getNetworkType("0973123456") //CDMA 800Hz
```
#### Phone Number Extraction
Extract the list of burmese phone numbers within an input. **This is experimental features, so feel free to report bugs if you use it!**
```kotlin
val extractor = MyanmarPhoneNumberExtractor()
val input = " () ()"
val result = extractor.extract(input) //[091234567, 091234566]
```
### Usage
If you use gradle, include
```
repositories {
mavenCentral()
}
implementation 'dev.aungkyawpaing.mmphonenumber:mmphonenumber:1.1.1'
```
**VERSION LOWER THAN 1.1.1 IS PUBLISHED ON JCENTER**
### Credit
- [myanmar-phonenumber.js](https://github.com/kaungmyatlwin/myanmar-phonenumber)
- [Kaung Myat Lwin](https://github.com/kaungmyatlwin) for giving me some pointers in porting
### License
```
Copyright 2019 Aung Kyaw Paing
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
近期下载者:
相关文件:
收藏者: