-
-
Notifications
You must be signed in to change notification settings - Fork 2k
utils.js
utils.js (found in build/js/) 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.
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)
intlTelInputUtils.formatNumber("07733123456", "gb", intlTelInputUtils.numberFormat.INTERNATIONAL);
// returns "+44 7733 123456"
getExampleNumber(countryCode, isNational, numberType)
Get an example number for the given country. isNational
is a boolean, numberType is a numberType
enum.
intlTelInputUtils.getExampleNumber("gb", true, intlTelInputUtils.numberType.FIXED_LINE);
// returns "0121 234 5678"
getNumberType(number, countryCode)
Get the type of the given number (returns a numberType
enum).
intlTelInputUtils.getNumberType("07733123456", "gb");
// returns 1 (which is equal to intlTelInputUtils.numberType.MOBILE)
getValidationError(number, countryCode)
If a number is invalid, then you can call this to get the reason (returns a validationError
enum).
intlTelInputUtils.getValidationError("07733123455555555", "gb");
// returns 3 (which is equal to intlTelInputUtils.validationError.TOO_LONG)
isValidNumber(number, countryCode)
Return a boolean for if the given number is valid.
intlTelInputUtils.isValidNumber("07733123455555555", "gb");
// returns false
See the source 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