-
-
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)
var formattedNumber = intlTelInputUtils.formatNumber("07733123456", "gb", intlTelInputUtils.numberFormat.INTERNATIONAL);
// "+44 7733 123456"
getExampleNumber(countryCode, isNational, numberType)
Get an example number for the given country. isNational
is a boolean, numberType is a numberType
enum.
var exampleNumber = intlTelInputUtils.getExampleNumber("gb", true, intlTelInputUtils.numberType.FIXED_LINE);
// "0121 234 5678"
getNumberType(number, countryCode)
Get the type of the given number (returns a numberType
enum).
var numberType = intlTelInputUtils.getNumberType("07733123456", "gb");
switch (numberType) {
case intlTelInputUtils.numberType.MOBILE:
// do something
...
}
getValidationError(number, countryCode)
If a number is invalid, then you can call this to get the reason (returns a validationError
enum).
var validationError = intlTelInputUtils.getValidationError("07733123455555555", "gb");
switch (validationError) {
case intlTelInputUtils.validationError.TOO_LONG:
// do something
...
}
isValidNumber(number, countryCode)
Return a boolean for if the given number is valid.
var isValidNumber = intlTelInputUtils.isValidNumber("07733123455555555", "gb");
// 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