getNumberType

getNumberType(number) is used to gets the type of a valid phone number.

Usage

Using Standard JavaScript:

// Create an instance of PhoneNumberUtil
const phoneUtil = require('libphonenumbers').PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Get type of phone number
console.log(phoneUtil.getNumberType(number));
// 2 // FIXED_LINE_OR_MOBILE

Using ECMAScript (ES):

import libphonenumbers from 'libphonenumbers';
// Create an instance of PhoneNumberUtil
const phoneUtil = libphonenumbers.PhoneNumberUtil.getInstance();
// Parse number with US country code and keep raw input
const number = phoneUtil.parseAndKeepRawInput('202-456-2121', 'US');
// Get type of phone number
console.log(phoneUtil.getNumberType(number));
// 2 // FIXED_LINE_OR_MOBILE

PhoneNumberType

The following enums is used to compare with the output of getNumberType(number).

EnumValue
FIXED_LINE0
MOBILE1
FIXED_LINE_OR_MOBILE2
TOLL_FREE3
PREMIUM_RATE4
SHARED_COST5
VOIP6
PERSONAL_NUMBER7
PAGER8
UAN9
VOICEMAIL10
UNKNOWN11