ug-phone-validator

1.0.0 • Public • Published

A lite phone validator for Ugandan numbers

This is a lite package to validate ugandan phone numbers based on the formats set by Uganda Communication Commission (UCC) as in this link

Use cases

  • Validate phone
  • Determine whether a number is office line, mobile number or toll free number excluding numbers like 112, 999
  • Determine telecom company the number belongs to

Installation

$ npm install ug-phone-validator --save

or

yarn add ug-phone-validator

Usage

The module accepts the various Number format +2567XXXXXXXX, 2567XXXXXXXX, 07XXXXXXXX, 7XXXXXXXX

However the module returns the phone number in the format 7XXXXXXXX

Here is the implementation:

const {validateUGPhone} = require('ug-phone-validator')

validateUGPhone("+256772100100") //returns JSON object
validateUGPhone("256772100100") //returns JSON object
validateUGPhone("0772100100") //returns JSON object
validateUGPhone("772100100") //returns JSON object

valid phone number response

    {
    "phone": "772100100",
    "valid": true,
    "info": "Is valid ugandan phone number",
    "telco": "MTN Uganda",
    "type": "mobile"
    }

An invalid phone number response

{
  "phone": "25688200567563",
  "valid": false,
  "info": "Phone number 25688200567563 is not a valid ugandan number",
  "telco": "unknown",
  "type": "unknow"
}

MORE OPTIONS

To simply determine if a number is valid or not

validateUGPhone("+256772100100").valid ; // true 

To get only the phone number telecom provider

validateUGPhone("+256772100100").telco ; // MTN Uganda 

To get simply determine if a number an office line, mobile or toll free

validateUGPhone("+256772100100").type ; // mobile 

Reporting bugs

For any issues, you may create one click here

Licence

MIT

Package Sidebar

Install

npm i ug-phone-validator

Weekly Downloads

3

Version

1.0.0

License

MIT

Unpacked Size

8.52 kB

Total Files

7

Last publish

Collaborators

  • alexxsanya