/ug-phone-wizard

Check Validity and Providers of Ugandan phone numbers

Primary LanguageJavaScriptMIT LicenseMIT

Codacy Badge Maintainability Test Coverage

ug-phone

Check Validity and Service Providers of Ugandan phone numbers

Installation

Use the node package manager npm to install ug-phone.

npm install ug-phone

Usage

Include in your project

ES5

const ugPhone = require("ug-phone");

ES6

import ugPhone from "ug-phone";

Check if phone number is in valid Ugandan format

ugPhone.isUgandanNumber("0755128879", [bool:validateLandline]);
// returns true

By default, landline numbers are accepted, second argument is optional and true by default

Get network service provider of a given phone number

ugPhone.getUgandanProvider("+256755128879", [boolean:acceptLandline]);
// returns Airtel
// 
Note

This method returns null if no match is found

By default, landline numbers are accepted, second argument is optional and true by default

Valid number criteria

Mobile

  • Begins with 2567 or 07 or +2567 followed by exactly 8 digits

Landline

  • Begins with 256 or 0 or +256 followed 20 or 31 or 39 followed by exactly 8 digits

Valid number examples

Mobile
  • 07712345678
  • +256712345678
  • 256712345678
Landline
  • 0202345678
  • 256392345678
  • +256312345678

Available service providers

  • Airtel
  • MTN
  • Africell
  • Uganda Telecom
  • LycaMobile
  • Smile Telecom

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT