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).
| Enum | Value | 
|---|---|
| FIXED_LINE | 0 | 
| MOBILE | 1 | 
| FIXED_LINE_OR_MOBILE | 2 | 
| TOLL_FREE | 3 | 
| PREMIUM_RATE | 4 | 
| SHARED_COST | 5 | 
| VOIP | 6 | 
| PERSONAL_NUMBER | 7 | 
| PAGER | 8 | 
| UAN | 9 | 
| VOICEMAIL | 10 | 
| UNKNOWN | 11 |