Coder Social home page Coder Social logo

miles-pudge-halter / myanmar-phonenumber-kt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vincent-paing/myanmar-phonenumber-kt

0.0 0.0 0.0 86 KB

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.

License: Apache License 2.0

Kotlin 100.00%

myanmar-phonenumber-kt's Introduction

Download Build Status

Kotlin port of 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
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.

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

MyanmarPhoneNumberUtils.isValidMyanmarPhoneNumber("09978412345") //true
MyanmarPhoneNumberUtils.isValidMyanmarPhoneNumber("14155552671") //false

Opreator Checking

Check which opreator the number is from

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

MyanmarPhoneNumberUtils.getNetworkType("09978412345") //GSM
MyanmarPhoneNumberUtils.getNetworkType("09451212123") //WCDMA
MyanmarPhoneNumberUtils.getNetworkType("096355555") //CDMA 450Hz
MyanmarPhoneNumberUtils.getNetworkType("0973123456") //CDMA 800Hz

Usage

If you use gradle, include

repositories {
    jcenter()
}

implementation 'com.aungkyawpaing.mmphonenumber:mmphonenumber:1.0.1'

Credit

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.

myanmar-phonenumber-kt's People

Contributors

vincent-paing avatar miles-pudge-halter avatar soethiha avatar soethihatun avatar

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.