This is a simple npm package that validates the structure and format phone numbers from Rwanda.
npm install dev-rw-phone
or
yarn add dev-rw-phone
// Load full build
const { phone } = require("dev-rw-phone");
console.log(phone("0780000000"));
// {
// isOk: true,
// error: null,
// normalized: "250780000000",
// formatted: "(+250) 780 000 000",
// telco: "MTN",
// short: "780000000"
// }
console.log(phone("80000000"));
// {
// isOk: false,
// error: "Phone number NOT valid",
// normalized: "80000000",
// formatted: "(+250) 7XX XXX XXX",
// telco: null,
// short: "7XXXXXXXX"
// }
const { isOk } = require("dev-rw-phone");
console.log(isOk("0780000000"));
// true
Or
phone("0780000000").isOk;
const { format } = require("dev-rw-phone");
console.log(format("0780000000"));
// "(+250) 780 000 000"
Or
phone("0780000000").formatted;
const { normalize } = require("dev-rw-phone");
console.log(normalize("0780000000"));
// "250780000000"
Or
phone("0780000000").normalized;
const { short } = require("dev-rw-phone");
console.log(short("0780000000"));
// "780000000"
Or
phone("0780000000").short;
const { telco } = require("dev-rw-phone");
console.log(telco("0780000000"));
// "MTN"
Or
phone("0780000000").telco;
const { phone } = require("dev-rw-phone");
console.log(phone("0780000000"));
// {
// isOk: true,
// error: null,
// normalized: "250780000000",
// formatted: "(+250) 780 000 000",
// telco: "MTN",
// short: "780000000"
// }
![]() Alleluia M |
---|
MIT
Alleluia M