Skip to content

utils.js

Jack O'Connor edited this page Feb 13, 2016 · 14 revisions

utils.js (found in lib/libphonenumber/build/) is a custom build of Google's libphonenumber library. It provides the following methods/enums, all namespaced under the global intlTelInputUtils, which are used by the plugin, but can also be used directly by you if needed.

Methods

Note: countryCode is optional (you can pass null) if number is a full international number.

formatNumber(number, countryCode, format)
Format the given number according to the given format (a numberFormat enum)

getExampleNumber(countryCode, isNational, format)
Get an example number for the given country. isNational is a bool, format is a numberFormat enum.

getNumberType(number, countryCode)
Get the type of the given number (returns a numberType enum).

getValidationError(number, countryCode)
If a number is invalid, then you can call this to get the reason (returns a validationError enum).

isValidNumber(number, countryCode)
Return a boolean for if the given number is valid.

Enums

See the build file for more info - the enums are towards the end.

numberFormat
e.g. INTERNATIONAL, NATIONAL

numberType
e.g. FIXED_LINE, MOBILE

validationError
e.g. INVALID_COUNTRY_CODE, TOO_SHORT

Clone this wiki locally