Skip to content

Repository files navigation

npm i bd-phone-number-validator

npm npm

A npm package to validate Bangladeshi phone numbers and identify their mobile operator. Ships with full TypeScript support.

Features

  • Validates any Bangladeshi phone number (+8801 / 8801 / 01 formats)
  • Identifies the operator (GrameenPhone, Banglalink, Teletalk, Airtel, Robi)
  • Returns a typed result object with full number info
  • Zero runtime dependencies

Installation

npm i bd-phone-number-validator

Usage

CommonJS

const { validate, operator } = require("bd-phone-number-validator");

console.log(validate("01700000000"));  // true
console.log(validate("01000000000"));  // false

console.log(operator("01700000000"));
// {
//   phoneNumber: '01700000000',
//   isValid: true,
//   operator: 'GrameenPhone',
//   operator_status: '(017) is a valid operator'
// }

TypeScript

import { validate, operator, PhoneNumberInfo } from "bd-phone-number-validator";

const isValid: boolean = validate("01700000000");

const info: PhoneNumberInfo = operator("01700000000");

API

validate(phoneNumber: string): boolean

Returns true if the number is a valid Bangladeshi mobile number, false otherwise.

Accepted formats: 01XXXXXXXXX (11 digits), 8801XXXXXXXXX (13 digits), +8801XXXXXXXXX (14 digits).

operator(phoneNumber: string): PhoneNumberInfo

Returns a PhoneNumberInfo object:

{
  phoneNumber: string;      // the input number
  isValid: boolean;         // whether the number is valid
  operator: string;         // operator name, or 'No match found!'
  operator_status: string;  // human-readable status message
}

Output

bd-phone-number-validator

Development

npm run build          # compile TypeScript
npm test               # run test suite
npm run test:coverage  # run tests with coverage report
npm run lint           # lint with ESLint

Authors

@MHNahib

portfolio portfolio linkedin twitter

License

MIT

About

bd-phone-number-validator is a npm package designed to validate phone number of bangladesh. It can validates any Bangladeshi cell phone numbers and show all the information about the phone numbers operator.

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages