isValidShortNumber

isValidShortNumber(number) is used to checks whether a short number is a valid number.

Usage

Using Standard JavaScript:

// Get an instance of ShortNumberInfo
const shortInfo = require('libphonenumbers').ShortNumberInfo.getInstance();
// Get 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');
// Check 202-456-2121 is valid short number
console.log(shortInfo.isValidShortNumber(number));
// false

Using ECMAScript (ES):

import libphonenumbers from 'libphonenumbers';
// Get an instance of ShortNumberInfo
const shortInfo = libphonenumbers.ShortNumberInfo.getInstance();
// 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');
// Check 202-456-2121 is valid short number
console.log(shortInfo.isValidShortNumber(number));
// false