npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

phonenum-info

v3.0.3

Published

Npm to check the phone number's validity

Downloads

10

Readme

Phone Number Validator 📞

A simple and powerful phone number validation library that uses the google-libphonenumber library to check if a phone number is valid for a specific region. It also provides formatted output for different international and regional formats.


Features 🚀

  • Validate Phone Number: Check if a phone number is valid for a given region.
  • Format Phone Number: Get different formats for the phone number (E164, National, International).
  • Support for Multiple Regions: Validates phone numbers for all supported regions using the country code.
  • Detailed Phone Number Information: Get information like the type of phone number (mobile, fixed line, etc.) and region.

Installation 🔧

To install the library, run the following npm command:

npm install phonenum-info

## Usage 📚

1. Validate a Phone Number ✅
To validate a phone number for a specific country/region code, use the isValidPhonenumber function.

```javascript
const { isValidPhonenumber } = require('phonenum-info');

const phoneNumber = '7XXXXX0519'; // Example phone number
const regionCode = 'IQ'; // Region code (e.g., IQ for Iraq)

if (isValidPhonenumber(phoneNumber, regionCode)) {
  console.log("Phone number is valid.");
} else {
  console.log("Phone number is invalid.");
}


2. Get Phone Number Information ℹ️
To retrieve detailed information about the phone number, including its type, country code, and formatted outputs, use the phonenumbervalidator function.

```javascript
const { phonenumbervalidator } = require('phonenum-info');

const phoneNumber = '7XXXXX0519'; // Example phone number
const regionCode = 'IQ'; // Region code (e.g., IQ for Iraq)

const result = phonenumbervalidator(phoneNumber, regionCode);
console.log(result);

This will output something like:


7XXXXX0519 is a VALID MOBILE phone number for region - IQ

Phone Number Info:
-------------------
Country Code          : 964
Raw Input             : 7XXXXX0519
Region Code           : IQ

Various Formats:
----------------
E164 Format           : +9647XXXXX0519
Original Format       : 7XXXXX0519
National Format       : 07XXXXX0519
International Format  : +964 7XX XXX 0519

3. Find Possible Matches for a Phone Number 🔍
To find possible phone number matches across multiple regions, use the possibilityOfPhoneNumber function.

```javascript
const { possibilityOfPhoneNumber } = require('phonenum-info');

const phoneNumber = '7XXXXX0519'; // Example phone number
const result = possibilityOfPhoneNumber(phoneNumber, true); // `true` for detailed info

console.log(result);

This will return an array of possible matches across different regions.


[
  '7XXXXX0519 is a VALID FIXED LINE phone number for region - DE\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 49\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : DE\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +497XXXXX0519\n' +
    '  Original Format       : 07XXX XX0519\n' +
    '  National Format       : 07XXX XX0519\n' +
    '  International Format  : +49 7XXX XX0519',
  '7XXXXX0519 is a VALID MOBILE phone number for region - IN\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 91\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : IN\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +917XXXXX0519\n' +
    '  Original Format       : 07XXXX X0519\n' +
    '  National Format       : 07XXXX X0519\n' +
    '  International Format  : +91 7XXXX X0519',
  '7XXXXX0519 is a VALID FIXED LINE phone number for region - IR\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 98\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : IR\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +987XXXXX0519\n' +
    '  Original Format       : 07X XXX 0519\n' +
    '  National Format       : 07X XXX 0519\n' +
    '  International Format  : +98 7X XXX 0519',
  '7XXXXX0519 is a VALID MOBILE phone number for region - IQ\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 964\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : IQ\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +9647XXXXX0519\n' +
    '  Original Format       : 07XX XXX 0519\n' +
    '  National Format       : 07XX XXX 0519\n' +
    '  International Format  : +964 7XX XXX 0519',
  '7XXXXX0519 is a VALID FIXED LINE phone number for region - LU\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 352\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : LU\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +3527XXXXX0519\n' +
    '  Original Format       : 7X XX XX 0519\n' +
    '  National Format       : 7X XX XX 0519\n' +
    '  International Format  : +352 7X XX XX 0519',
  '7XXXXX0519 is a VALID MOBILE phone number for region - GB\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 44\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : GB\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +447XXXXX0519\n' +
    '  Original Format       : 07XXX XX0519\n' +
    '  National Format       : 07XXX XX0519\n' +
    '  International Format  : +44 7XXX XX0519',
  '7XXXXX0519 is a VALID FIXED LINE OR MOBILE phone number for region - US\n' +
    '  \n' +
    '  Phone Number Info:\n' +
    '  -------------------\n' +
    '  Country Code          : 1\n' +
    '  Raw Input             : 7XXXXX0519\n' +
    '  Region Code           : US\n' +
    '  \n' +
    '  Various Formats:\n' +
    '  ----------------\n' +
    '  E164 Format           : +17XXXXX0519\n' +
    '  Original Format       : (7XX) XXX-0519\n' +
    '  National Format       : (7XX) XXX-0519\n' +
    '  International Format  : +1 7XX-XXX-0519'
]

Alternatively, you can use false for more concise results:

const { possibilityOfPhoneNumber } = require('phonenum-info');

const phoneNumber = '7XXXXX0519'; // Example phone number
const result = possibilityOfPhoneNumber(phoneNumber, false); // `false` for concise info

console.log(result);

This will return a simplified array:

[
  {
    "Country": "Germany",
    "Number Type": "FIXED LINE",
    "International Format": "+49 7XXX XX0519"
  },
  {
    "Country": "India",
    "Number Type": "MOBILE",
    "International Format": "+91 7XXXX X0519"
  },
  {
    "Country": "Iran",
    "Number Type": "FIXED LINE",
    "International Format": "+98 7X XXXX 0519"
  },
  {
    "Country": "Iraq",
    "Number Type": "MOBILE",
    "International Format": "+964 7XX XXX 0519"
  },
  {
    "Country": "Luxembourg",
    "Number Type": "FIXED LINE",
    "International Format": "+352 7X XX XX 0519"
  },
  {
    "Country": "United Kingdom",
    "Number Type": "MOBILE",
    "International Format": "+44 7XXX XX0519"
  },
  {
    "Country": "United States",
    "Number Type": "FIXED LINE OR MOBILE",
    "International Format": "+1 7XX-XXX-0519"
  }
]

4. Find Country Name from Region Code 🌍
You can also get the country name based on the region code.

```javascript
const { findCountryName } = require('phonenum-info');

const regionCode = 'IQ'; // Region code (e.g., IQ for Iraq)
const countryName = findCountryName(regionCode);
console.log(countryName); // Outputs: "Iraq"

# Available Functions 📜
isValidPhonenumber(num, code)
 Parameters:

  1. num (string): The phone number to validate.

  2. code (string): The region code (ISO 3166-1 alpha-2).

Returns: true if the phone number is valid for the given region, otherwise false.

phonenumbervalidator(num, code)
 Parameters:

   1. num (string): The phone number to validate.

   2. code (string): The region code (ISO 3166-1 alpha-2).

Returns: A formatted string containing phone number information, or a message saying it is invalid.

possibilityOfPhoneNumber(num, needNumberDetailInfo)
 Parameters:

    1. num (string): The phone number to check.

    2. needNumberDetailInfo (boolean): Whether to include detailed information for each match (optional, default: false).

Returns: An array of objects or strings with the possible phone number matches across multiple regions.

findCountryName(code)
 Parameters:

    1. code (string): The region code (ISO 3166-1 alpha-2).

Returns: The name of the country for the given region code, or null if not found.


# License 📜
This library is open-source and released under the MIT License.