intl-tel-input 26.0.6 → 26.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +4 -582
  2. package/angular/README.md +10 -10
  3. package/angular/build/IntlTelInput.js +7 -1
  4. package/angular/build/IntlTelInputWithUtils.js +7 -1
  5. package/build/css/intlTelInput-no-assets.css +7 -0
  6. package/build/css/intlTelInput-no-assets.min.css +1 -1
  7. package/build/css/intlTelInput.css +6 -0
  8. package/build/css/intlTelInput.min.css +1 -1
  9. package/build/js/data.js +1 -1
  10. package/build/js/data.min.js +1 -1
  11. package/build/js/intlTelInput.js +8 -2
  12. package/build/js/intlTelInput.min.js +2 -2
  13. package/build/js/intlTelInputWithUtils.js +8 -2
  14. package/build/js/intlTelInputWithUtils.min.js +2 -2
  15. package/package.json +1 -1
  16. package/react/README.md +7 -7
  17. package/react/build/IntlTelInput.cjs +7 -1
  18. package/react/build/IntlTelInput.js +7 -1
  19. package/react/build/IntlTelInputWithUtils.cjs +7 -1
  20. package/react/build/IntlTelInputWithUtils.js +7 -1
  21. package/svelte/README.md +9 -9
  22. package/svelte/build/IntlTelInput.mjs +93 -93
  23. package/svelte/build/IntlTelInputWithUtils.mjs +2 -2
  24. package/vue/README.md +7 -7
  25. package/vue/build/exports/IntlTelInput.mjs +1 -1
  26. package/vue/build/exports/IntlTelInputWithUtils.mjs +1 -1
  27. package/vue/build/{intl-tel-input-zNYByxVM.mjs → intl-tel-input-DPowcCQW.mjs} +2 -2
  28. package/build/js/i18n/ar/countries.js +0 -245
  29. package/build/js/i18n/ar/interface.js +0 -23
  30. package/build/js/i18n/bg/countries.js +0 -245
  31. package/build/js/i18n/bg/interface.js +0 -13
  32. package/build/js/i18n/bn/countries.js +0 -245
  33. package/build/js/i18n/bn/interface.js +0 -13
  34. package/build/js/i18n/bs/countries.js +0 -245
  35. package/build/js/i18n/bs/interface.js +0 -20
  36. package/build/js/i18n/ca/countries.js +0 -245
  37. package/build/js/i18n/ca/interface.js +0 -13
  38. package/build/js/i18n/cs/countries.js +0 -245
  39. package/build/js/i18n/cs/interface.js +0 -20
  40. package/build/js/i18n/da/countries.js +0 -245
  41. package/build/js/i18n/da/interface.js +0 -13
  42. package/build/js/i18n/de/countries.js +0 -245
  43. package/build/js/i18n/de/interface.js +0 -13
  44. package/build/js/i18n/ee/countries.js +0 -245
  45. package/build/js/i18n/ee/index.js +0 -18
  46. package/build/js/i18n/ee/interface.js +0 -13
  47. package/build/js/i18n/el/countries.js +0 -245
  48. package/build/js/i18n/el/interface.js +0 -13
  49. package/build/js/i18n/en/countries.js +0 -245
  50. package/build/js/i18n/en/interface.js +0 -14
  51. package/build/js/i18n/es/countries.js +0 -245
  52. package/build/js/i18n/es/interface.js +0 -13
  53. package/build/js/i18n/fa/countries.js +0 -245
  54. package/build/js/i18n/fa/interface.js +0 -13
  55. package/build/js/i18n/fi/countries.js +0 -245
  56. package/build/js/i18n/fi/interface.js +0 -13
  57. package/build/js/i18n/fr/countries.js +0 -245
  58. package/build/js/i18n/fr/interface.js +0 -13
  59. package/build/js/i18n/hi/countries.js +0 -245
  60. package/build/js/i18n/hi/interface.js +0 -13
  61. package/build/js/i18n/hr/countries.js +0 -245
  62. package/build/js/i18n/hr/interface.js +0 -20
  63. package/build/js/i18n/hu/countries.js +0 -245
  64. package/build/js/i18n/hu/interface.js +0 -13
  65. package/build/js/i18n/id/countries.js +0 -245
  66. package/build/js/i18n/id/interface.js +0 -13
  67. package/build/js/i18n/it/countries.js +0 -245
  68. package/build/js/i18n/it/interface.js +0 -13
  69. package/build/js/i18n/ja/countries.js +0 -245
  70. package/build/js/i18n/ja/interface.js +0 -13
  71. package/build/js/i18n/ko/countries.js +0 -245
  72. package/build/js/i18n/ko/interface.js +0 -13
  73. package/build/js/i18n/lt/countries.js +0 -245
  74. package/build/js/i18n/lt/interface.js +0 -26
  75. package/build/js/i18n/mr/countries.js +0 -245
  76. package/build/js/i18n/mr/interface.js +0 -13
  77. package/build/js/i18n/nl/countries.js +0 -245
  78. package/build/js/i18n/nl/interface.js +0 -13
  79. package/build/js/i18n/no/countries.js +0 -245
  80. package/build/js/i18n/no/interface.js +0 -13
  81. package/build/js/i18n/pl/countries.js +0 -245
  82. package/build/js/i18n/pl/interface.js +0 -19
  83. package/build/js/i18n/pt/countries.js +0 -245
  84. package/build/js/i18n/pt/interface.js +0 -13
  85. package/build/js/i18n/ro/countries.js +0 -245
  86. package/build/js/i18n/ro/interface.js +0 -18
  87. package/build/js/i18n/ru/countries.js +0 -245
  88. package/build/js/i18n/ru/interface.js +0 -20
  89. package/build/js/i18n/sk/countries.js +0 -245
  90. package/build/js/i18n/sk/interface.js +0 -20
  91. package/build/js/i18n/sl/countries.js +0 -245
  92. package/build/js/i18n/sl/interface.js +0 -25
  93. package/build/js/i18n/sq/countries.js +0 -245
  94. package/build/js/i18n/sq/interface.js +0 -14
  95. package/build/js/i18n/sr/countries.js +0 -245
  96. package/build/js/i18n/sr/interface.js +0 -21
  97. package/build/js/i18n/sv/countries.js +0 -245
  98. package/build/js/i18n/sv/interface.js +0 -13
  99. package/build/js/i18n/te/countries.js +0 -245
  100. package/build/js/i18n/te/interface.js +0 -13
  101. package/build/js/i18n/th/countries.js +0 -245
  102. package/build/js/i18n/th/interface.js +0 -13
  103. package/build/js/i18n/tr/countries.js +0 -245
  104. package/build/js/i18n/tr/interface.js +0 -13
  105. package/build/js/i18n/uk/countries.js +0 -245
  106. package/build/js/i18n/uk/interface.js +0 -20
  107. package/build/js/i18n/ur/countries.js +0 -245
  108. package/build/js/i18n/ur/interface.js +0 -13
  109. package/build/js/i18n/uz/countries.js +0 -245
  110. package/build/js/i18n/uz/interface.js +0 -13
  111. package/build/js/i18n/vi/countries.js +0 -245
  112. package/build/js/i18n/vi/interface.js +0 -13
  113. package/build/js/i18n/zh/countries.js +0 -245
  114. package/build/js/i18n/zh/interface.js +0 -13
  115. package/build/js/i18n/zh-hk/countries.js +0 -245
  116. package/build/js/i18n/zh-hk/interface.js +0 -14
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - More control over number extensions
10
10
  - Lots of other fixes and improvements
11
11
 
12
- International Telephone Input is a JavaScript plugin for entering and validating international telephone numbers. It takes a regular input field, adds a searchable country dropdown, auto-detects the user's country, displays a relevant placeholder number, formats the number as you type, and provides comprehensive validation methods. [React](https://github.com/jackocnr/intl-tel-input/blob/master/react/README.md), [Vue](https://github.com/jackocnr/intl-tel-input/blob/master/vue/README.md), [Angular](https://github.com/jackocnr/intl-tel-input/blob/master/angular/README.md) and [Svelte (beta)](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/README.md) components are also included.
12
+ International Telephone Input is a JavaScript plugin for entering, formatting and validating international telephone numbers. It takes a regular input field, adds a searchable country dropdown, auto-detects the user's country, displays a relevant placeholder number, formats the number as you type, and provides comprehensive validation methods. [React](https://github.com/jackocnr/intl-tel-input/blob/master/react/README.md), [Vue](https://github.com/jackocnr/intl-tel-input/blob/master/vue/README.md), [Angular](https://github.com/jackocnr/intl-tel-input/blob/master/angular/README.md) and [Svelte (beta)](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/README.md) components are also included.
13
13
 
14
14
  <picture>
15
15
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-dark.png">
@@ -24,37 +24,11 @@ If you find the plugin helpful, please consider [supporting the project](https:/
24
24
 
25
25
  Use [Twilio's API to build phone verification, SMS 2FA, appointment reminders, marketing notifications and so much more](https://www.twilio.com/blog/international-telephone-input-twilio?utm_source=github&utm_medium=referral&utm_campaign=intl_tel_input). We can't wait to see what you build.
26
26
 
27
- ## Table of Contents
28
-
29
- - [React, Vue, Angular and Svelte Components](#react-vue-angular-and-svelte-components)
30
- - [Demo and Examples](#demo-and-examples)
31
- - [Mobile](#mobile)
32
- - [Features](#features)
33
- - [Getting Started](#getting-started-using-a-cdn)
34
- - [Recommended Usage](#recommended-usage)
35
- - [Initialisation Options](#initialisation-options)
36
- - [Instance Methods](#instance-methods)
37
- - [Static Methods](#static-methods)
38
- - [Events](#events)
39
- - [Theming / Dark Mode](#theming--dark-mode)
40
- - [Utilities Script](#utilities-script)
41
- - [Loading The Utilities Script](#loading-the-utilities-script)
42
- - [Troubleshooting](#troubleshooting)
43
- - [Contributing](#contributing)
44
- - [Attributions](#attributions)
45
-
46
27
  ## React, Vue, Angular and Svelte Components
47
- We now provide React, Vue, Angular and Svelte (beta) components alongside the regular JavaScript plugin. This readme is for the JavaScript plugin. View the [React Component](https://github.com/jackocnr/intl-tel-input/blob/master/react/README.md), the [Vue Component](https://github.com/jackocnr/intl-tel-input/blob/master/vue/README.md) the [Angular Component](https://github.com/jackocnr/intl-tel-input/blob/master/angular/README.md), or the [Svelte component (beta)](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/README.md).
48
-
49
- ## Demo and Examples
50
- View the [live demo](https://intl-tel-input.com) for examples of how to use the various options, along with the relevant code snippets. Or play with the options yourself on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--vanilla).
51
-
52
- Alternatively, download and build the project yourself in 3 simple steps. You just need to initialise the submodules with `git submodule update --init --recursive`, then run `npm install`, and then `npm run build`. You should now be able to open the included demo.html in your browser and have a working plugin!
28
+ We provide React, Vue, Angular and Svelte (beta) components alongside the regular JavaScript plugin. This readme is for the JavaScript plugin. View the [React Component](https://github.com/jackocnr/intl-tel-input/blob/master/react/README.md), the [Vue Component](https://github.com/jackocnr/intl-tel-input/blob/master/vue/README.md) the [Angular Component](https://github.com/jackocnr/intl-tel-input/blob/master/angular/README.md), or the [Svelte component (beta)](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/README.md).
53
29
 
54
- ## Mobile
55
- By default, on mobile devices, we show a fullscreen popup instead of the inline dropdown to make better use of the limited screen space. This is similar to how a native `<select>` element works. You can control this behaviour with the `useFullscreenPopup` option. The popup can be closed by either selecting a country from the list or by tapping on the grey area on the sides. [See example](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--usefullscreenpopup) (using the React component).
56
-
57
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/mobile2.png" alt="Mobile screenshot" width="270" height="512" />
30
+ ## Docs and Examples
31
+ We have a newly updated website, where you can find [a full set of docs](https://intl-tel-input.com/docs/getting-started.html), a [live playground](https://intl-tel-input.com/playground/) where you can try out all of the options, as well as plenty of [examples](https://intl-tel-input.com/examples/validation-practical.html) of different setups.
58
32
 
59
33
  ## Features
60
34
  * Automatically select the user's current country using an IP lookup
@@ -72,558 +46,6 @@ By default, on mobile devices, we show a fullscreen popup instead of the inline
72
46
  * Translations provided in over 40 languages, as well as support for RTL layout and alternative numeral sets
73
47
  * Lots of initialisation options for customisation, as well as instance methods/events for interaction
74
48
 
75
- ## Getting Started (Using a CDN)
76
- 1. Add the CSS
77
- ```html
78
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@26.0.6/build/css/intlTelInput.css">
79
- ```
80
-
81
- 2. Add the plugin script and initialise it on your input element
82
- ```html
83
- <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@26.0.6/build/js/intlTelInput.min.js"></script>
84
- <script>
85
- const input = document.querySelector("#phone");
86
- window.intlTelInput(input, {
87
- loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@26.0.6/build/js/utils.js"),
88
- });
89
- </script>
90
- ```
91
-
92
- ## Getting Started (Using a bundler, e.g. Webpack)
93
- 1. Install with npm: `npm install intl-tel-input --save` or yarn: `yarn add intl-tel-input`
94
-
95
- 2. Import the CSS: `import 'intl-tel-input/build/css/intlTelInput.css';`
96
-
97
- 3. Set the path to flags.webp in your CSS, by overriding the CSS variables
98
- ```css
99
- .iti {
100
- --iti-path-flags-1x: url('path/to/flags.webp');
101
- --iti-path-flags-2x: url('path/to/flags@2x.webp');
102
- }
103
- ```
104
-
105
- 4. Import the JS and initialise the plugin on your input element
106
- ```js
107
- import intlTelInput from 'intl-tel-input';
108
-
109
- const input = document.querySelector("#phone");
110
- intlTelInput(input, {
111
- loadUtils: () => import("intl-tel-input/utils"),
112
- });
113
- ```
114
-
115
- Most bundlers (such as Webpack, Vite, or Parcel) will see this and place the [utilities script](#utilities-script) in a separate bundle and load it asynchronously, only when needed. If this doesn’t work with your bundler or you want to load the utils module from some other location (such as a CDN or your own hosted version), you can do that as well - see other examples.
116
-
117
- ## Getting Started (Not using a bundler)
118
- 1. Download the [latest release](https://github.com/jackocnr/intl-tel-input/releases/latest), or better yet install it with [npm](https://www.npmjs.com/package/intl-tel-input)
119
-
120
- 2. Add the stylesheet
121
- ```html
122
- <link rel="stylesheet" href="path/to/intlTelInput.css">
123
- ```
124
-
125
- 3. Set the path to flags.webp in your CSS, by overriding the CSS variables
126
- ```css
127
- .iti {
128
- --iti-path-flags-1x: url('path/to/flags.webp');
129
- --iti-path-flags-2x: url('path/to/flags@2x.webp');
130
- }
131
- ```
132
-
133
- 4. Add the plugin script and initialise it on your input element
134
- ```html
135
- <script src="path/to/intlTelInput.js"></script>
136
- <script>
137
- const input = document.querySelector("#phone");
138
- window.intlTelInput(input, {
139
- loadUtils: () => import("https://my-domain/path/to/utils.js"),
140
- });
141
- </script>
142
- ```
143
-
144
- ## Recommended Usage
145
- We highly recommend you [load the included utils.js](#loading-the-utilities-script), which enables formatting and validation, etc. Then the plugin is built to always deal with numbers in the full international format (e.g. "+17024181234") and convert them accordingly - even when `nationalMode` or `separateDialCode` is enabled. We recommend you get, store, and set numbers exclusively in this format for simplicity - then you don't have to deal with handling the country code separately, as full international numbers include the country code information*.
146
-
147
- You can always get the full international number (including country code) using `getNumber`, then you only have to store that one string in your database (you don't have to store the country separately), and then the next time you initialise the plugin with that number in the input, it will automatically set the country* and format it according to the options you specify (e.g. when using `nationalMode` it will automatically display the number in national format, removing the international dial code).
148
-
149
- If you know the user's country, you can set it with `initialCountry` (e.g. `"us"` for the United States). If you don't, we recommend setting `initialCountry` to `"auto"` (along with the `geoIpLookup` option) to determine the user's country based on their IP address - [see example](https://intl-tel-input.com/examples/lookup-country.html).
150
-
151
- If you know the user's language, you can use the included translations to localise the country names (etc) - [see example](https://intl-tel-input.com/examples/localise-countries.html).
152
-
153
- _*Except for some small satellite territories, which share number ranges with the main country (search data.ts for "shared" for examples). When displaying numbers from those shared ranges, we default to selecting the main country._
154
-
155
- ## Initialisation Options
156
- When you initialise the plugin, the first argument is the input element, and the second is an object containing any initialisation options you want, which are detailed below. Note: any options that take country codes should be [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) codes.
157
-
158
- **allowDropdown**
159
- Type: `Boolean` Default: `true`
160
- Whether or not to allow the dropdown. If disabled, there is no dropdown arrow, and the selected country is not clickable. Also, if showFlags is enabled, we display the selected flag on the right instead, because it is just a marker of state. Note that if `separateDialCode` is enabled, `allowDropdown` is forced to `true` as the dropdown is required when the user types "+" in this case. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--allowdropdown) (using the React component).
161
-
162
- **allowNumberExtensions**
163
- Type: `Boolean` Default: `false`
164
- Whether or not the validation methods return `true` for numbers containing extensions, e.g. "+1 702 123-1234 ext. 1234".
165
-
166
- **allowPhonewords**
167
- Type: `Boolean` Default: `false`
168
- Whether or not the validation methods return `true` for numbers containing phonewords, e.g. "+1 702 FLOWERS".
169
-
170
- **autoPlaceholder**
171
- Type: `String` Default: `"polite"`
172
- Set the input's placeholder to an example number for the selected country, and update it if the country changes. You can specify the number type using the `placeholderNumberType` option. By default, it is set to `"polite"`, which means it will only set the placeholder if the input doesn't already have one. You can also set it to `"aggressive"`, which will replace any existing placeholder, or `"off"`. Requires the [utils script to be loaded](#loading-the-utilities-script).
173
-
174
- **containerClass**
175
- Type: `String` Default: `""`
176
- Additional classes to add to the (injected) wrapper `<div>`.
177
-
178
- **countryNameLocale**
179
- Type: `String` Default: `"en"`
180
- The locale to pass to `Intl.DisplayNames` to generate the country names.
181
-
182
- **countryOrder**
183
- Type: `Array` Default: `null`
184
- Specify the ordering for the country list with an array of iso2 country codes. Any omitted countries will appear after those specified, in alphabetical order, e.g. setting `countryOrder` to `["jp", "kr"]` will result in the list: Japan, South Korea, Afghanistan, Albania, Algeria, etc. _Note: this replaces the legacy `preferredCountries` option (now removed)._
185
-
186
- **countrySearch**
187
- Type: `Boolean` Default: `true`
188
- Add a search input to the top of the dropdown, so users can filter the displayed countries.
189
-
190
- **customPlaceholder**
191
- Type: `Function` Default: `null`
192
- Change the placeholder generated by autoPlaceholder. Must return a string.
193
-
194
- ```js
195
- intlTelInput(input, {
196
- customPlaceholder: (selectedCountryPlaceholder, selectedCountryData) => "e.g. " + selectedCountryPlaceholder,
197
- });
198
- ```
199
-
200
- **dropdownContainer**
201
- Type: `Node` Default: `null`
202
- Expects a node, e.g. `document.body`. Instead of putting the country dropdown markup next to the input, append it to the specified node, and it will then be positioned next to the input using JavaScript (using `position: fixed`). This is useful when the input is inside a container with `overflow: hidden`. Note that the positioning is broken by scrolling, so the dropdown will automatically close on the `window` scroll event.
203
-
204
- **excludeCountries**
205
- Type: `Array` Default: `[]`
206
- In the dropdown, display all countries except the ones you specify here. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--excludecountries) (using the React component). Also see: `onlyCountries` option.
207
-
208
- **fixDropdownWidth**
209
- Type: `Boolean` Default: `true`
210
- Fix the dropdown width to the input width (rather than being as wide as the longest country name). Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--fixdropdownwidth) (using the React component).
211
-
212
- **formatAsYouType**
213
- Type: `Boolean` Default: `true`
214
- Automatically format the number as the user types. This feature will be disabled if the user types their own formatting characters. Requires the [utils script to be loaded](#loading-the-utilities-script). _Note: previously named `autoFormat`._
215
-
216
- **formatOnDisplay**
217
- Type: `Boolean` Default: `true`
218
- Format the input value (according to the `nationalMode` option) during initialisation, when a new country is selected, on `setNumber` and on `setCountry`. Requires the [utils script to be loaded](#loading-the-utilities-script).
219
-
220
- **geoIpLookup**
221
- Type: `Function` Default: `null`
222
- When setting `initialCountry` to `"auto"`, you must use this option to specify a custom function that calls an IP lookup service to get the user's location and then invokes the `success` callback with the relevant country code. Also note that when instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is returned under the `promise` instance property, so you can do something like `iti.promise.then(...)` to know when initialisation requests like this have completed.
223
-
224
- Here is an example using the [ipapi](https://ipapi.co/api/?javascript#location-of-clients-ip) service:
225
- ```js
226
- intlTelInput(input, {
227
- initialCountry: "auto",
228
- geoIpLookup: (success, failure) => {
229
- fetch("https://ipapi.co/json")
230
- .then((res) => res.json())
231
- .then((data) => success(data.country_code))
232
- .catch(() => failure());
233
- }
234
- });
235
- ```
236
- _Note that the `failure` callback must be called in the event of an error, hence the use of `catch()` in this example. Tip: store the result in a cookie to avoid repeat lookups!_
237
-
238
- **hiddenInput**
239
- Type: `Function` Default: `null`
240
- Allows the creation of hidden input fields within a form, which, on submit, get populated with (1) the full international telephone number and (2) the selected country code. It accepts a function that receives the name of the main telephone input as an argument. This function should return an object with `phone` and (optionally) `country` properties to specify the names of the hidden inputs for the phone number and country code, respectively. This is useful for old-fashioned, page-load form submissions to ensure the full international number and country code are captured, especially when `nationalMode` is enabled.
241
-
242
- ***Note**: This feature requires the input to be inside a `<form>` element, as it listens for the `submit` event on the closest form element. Also note that since this uses `getNumber` internally, firstly it requires the [utils script to be loaded](#loading-the-utilities-script), and secondly, it expects a valid number and so will only work correctly if you have used `isValidNumber` to validate the number before allowing the form submit to go through.
243
-
244
- ```js
245
- intlTelInput(input, {
246
- hiddenInput: (telInputName) => ({
247
- phone: "phone_full",
248
- country: "country_code"
249
- }),
250
- });
251
- ```
252
-
253
- This will generate the following (hidden) elements, which will be automatically populated on submit:
254
-
255
- ```html
256
- <input type="hidden" name="phone_full">
257
- <input type="hidden" name="country_code">
258
- ```
259
-
260
- **i18n**
261
- Type: `Object` Default: `{}`
262
- There are two aspects to the internationalisation of this plugin. The first is the country names, which are translated automatically using the native `Intl.DisplayNames` - just specify the locale you want using the `countryNameLocale` option. The second is the user interface strings (including the country search placeholder, search empty state, and various other strings for screen readers). We provide translations for these in <a href="https://github.com/jackocnr/intl-tel-input/tree/master/src/js/intl-tel-input/i18n">over 40 languages</a> - simply import the language module you need and pass it to the plugin using the `i18n` option (see option 1 below). You can also override one or more individual keys this way. Alternatively, you can provide your own custom translations (see option 2 below). If providing your own, please see the required UI strings listed below. [See example](https://intl-tel-input.com/examples/localise-countries.html). If we don't currently support a language you need, it's easy to [contribute this](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md#adding-a-new-translation) yourself - you only need to provide a handful of UI translation strings. _Note: previously named `localizedCountries`._
263
-
264
- Option 1: import one of the provided translation modules
265
- ```js
266
- import { fr } from "intl-tel-input/i18n";
267
-
268
- intlTelInput(input, {
269
- i18n: fr,
270
- });
271
-
272
- // or to override one or more keys, you could do something like this
273
- intlTelInput(input, {
274
- i18n: {
275
- ...fr,
276
- searchPlaceholder: "Recherche de pays",
277
- // or override a specific country name
278
- us: "United States",
279
- },
280
- });
281
- ```
282
-
283
- Option 2: define your own custom translations
284
- ```js
285
- intlTelInput(input, {
286
- i18n: {
287
- // Aria label for the selected country element, when there is a country selected
288
- selectedCountryAriaLabel: "Change country, selected ${countryName} (${dialCode})",
289
- // Aria label and title text for the selected country element, when no country is selected
290
- noCountrySelected: "Select country",
291
- // Aria label for the country list element
292
- countryListAriaLabel: "List of countries",
293
- // Placeholder for the search input in the dropdown
294
- searchPlaceholder: "Search",
295
- // Aria label for the clear search button
296
- clearSearchAriaLabel: "Clear search",
297
- // Visible text for when the search produces no results
298
- searchEmptyState: "No results found",
299
- // Screen reader summary of search results
300
- searchSummaryAria(count) {
301
- if (count === 0) return "No results found";
302
- if (count === 1) return "1 result found";
303
- return `${count} results found`;
304
- }
305
- }
306
- });
307
- ```
308
-
309
- **initialCountry**
310
- Type: `String` Default: `""`
311
- Set the initial country selection by specifying its country code, e.g. `"us"` for the United States. (Be careful not to do this unless you are sure of the user's country, as it can lead to tricky issues if set incorrectly and the user auto-fills their national number and submits the form without checking - in certain cases, this can pass validation and you can end up storing a number with the wrong dial code). You can also set `initialCountry` to `"auto"`, which will look up the user's country based on their IP address (requires the `geoIpLookup` option - [see example](https://intl-tel-input.com/examples/lookup-country.html)). Note: however you use `initialCountry`, it will not update the country selection if the input already contains a number with an international dial code.
312
-
313
- **loadUtils**
314
- Type: `() => Promise<module>` Default: `null`
315
- This is one way to lazy load the included utils.js (to enable formatting/validation, etc) - see [Loading The Utilities Script](#loading-the-utilities-script) for more options.
316
-
317
- The `loadUtils` option takes a function that returns a Promise resolving to the utils module. You can `import` the utils module in different ways (examples below): (A) from a CDN, (B) from your own hosted version of [utils.js](https://cdn.jsdelivr.net/npm/intl-tel-input@26.0.6/build/js/utils.js), or (C) if you use a bundler like Webpack, Vite or Parcel, you can import it directly from the package. _Note: this replaces the `utilsScript` option (now removed)._
318
-
319
- ```js
320
- // (A) import utils module from a CDN
321
- intlTelInput(htmlInputElement, {
322
- loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@26.0.6/build/js/utils.js"),
323
- });
324
-
325
- // (B) import utils module from your own hosted version of utils.js
326
- intlTelInput(htmlInputElement, {
327
- loadUtils: () => import("/path/to/utils.js"),
328
- });
329
-
330
- // (C) with a bundler, you can import the utils module directly from the package
331
- intlTelInput(htmlInputElement, {
332
- loadUtils: () => import("intl-tel-input/utils"),
333
- });
334
- ```
335
-
336
- The module is only loaded when you initialise the plugin, and additionally, only when the page has finished loading (on the window load event) to prevent blocking (the script is ~260KB). When instantiating the plugin, a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is returned under the `promise` instance property, so you can do something like `iti.promise.then(callback)` to know when initialisation requests like this have finished. See [Utilities Script](#utilities-script) for more information.
337
-
338
- If you want more control over when this file is lazy-loaded, you can manually invoke the `attachUtils` static method whenever you like, instead of using the `loadUtils` initialisation option.
339
-
340
- **nationalMode**
341
- Type: `Boolean` Default: `true`
342
- Format numbers in the national format, rather than the international format. This applies to placeholder numbers and when displaying users' existing numbers. Note that it's fine for users to type their numbers in national format - as long as they have selected the right country, you can use `getNumber` to extract a full international number - [see example](https://intl-tel-input.com/examples/national-mode.html). It is recommended to leave this option enabled to encourage users to enter their numbers in national format, as this is usually more familiar to them, and so it creates a better user experience.
343
-
344
- **onlyCountries**
345
- Type: `Array` Default: `[]`
346
- In the dropdown, display only the countries you specify - [see example](https://intl-tel-input.com/examples/only-countries.html). Also see: `excludeCountries` option.
347
-
348
- **placeholderNumberType**
349
- Type: `String` Default: `"MOBILE"`
350
- Specify [one of the keys](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L162) from the enum `intlTelInput.utils.numberType` (e.g. `"FIXED_LINE"`) to set the number type to use for the placeholder. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--placeholdernumbertype) (using the React component).
351
-
352
- **showFlags**
353
- Type: `Boolean` Default: `true`
354
- Set this to false to hide the flags, e.g. for political reasons. Instead, it will show a generic globe icon. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--showflags) (using the React component).
355
-
356
- **separateDialCode**
357
- Type: `Boolean` Default: `false`
358
- Display the selected country's international dial code next to the input, so it looks like it's part of the typed number. Since the user cannot edit the displayed dial code, they may try to type a new one - in this case, to avoid having two dial codes next to each other, we automatically open the country dropdown and put the newly typed dial code in the search input instead. So if they type +54, then Argentina will be highlighted in the dropdown, and they can simply press Enter to select it, updating the displayed dial code (this feature requires `allowDropdown` and `countrySearch` to be enabled). Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--separatedialcode) (using the React component). _Note: previously named `showSelectedDialCode`._
359
-
360
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/separate-dial-code4.png" width="267" height="51" alt="Separate Dial Code">
361
-
362
- **strictMode**
363
- Type: `Boolean` Default: `false`
364
- As the user types in the input, ignore any irrelevant characters. The user can only enter numeric characters and an optional plus at the beginning. Cap the length at the maximum valid number length (this respects `allowedNumberTypes`). Requires the [utils script to be loaded](#loading-the-utilities-script). [See example](https://intl-tel-input.com/examples/strict-mode.html).
365
-
366
- **useFullscreenPopup**
367
- Type: `Boolean` Default: `true on mobile devices, false otherwise`
368
- Control when the country list appears as a fullscreen popup vs an inline dropdown. By default, it will appear as a fullscreen popup on mobile devices (based on user-agent and screen width), to make better use of the limited space (similar to how a native `<select>` works), and as an inline dropdown on larger devices/screens. Play with this option on [Storybook](https://intl-tel-input.com/storybook/?path=/docs/intltelinput--usefullscreenpopup) (using the React component).
369
-
370
- **allowedNumberTypes**
371
- Type: `String[]` Default: `["MOBILE", "FIXED_LINE"]`
372
- Specify an array of [the keys](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L198) from the enum `intlTelInput.utils.numberType` to set the number type(s) to enforce during validation, as well as the number length to enforce with `strictMode`. Set it to `null` to not enforce any particular type. By default, it's set to `["MOBILE", "FIXED_LINE"]` so `isValidNumber` (etc) will only return `true` for those kinds of numbers. Alternatively, you could set it to simply `["MOBILE"]` if you only wanted to accept mobile numbers as valid. _Note: previously named `validationNumberTypes`._
373
-
374
- ## Instance Methods
375
- In these examples, `iti` refers to the plugin instance which gets returned when you initialise the plugin, e.g.
376
- ```js
377
- const iti = intlTelInput(input);
378
- ```
379
-
380
- **destroy**
381
- Remove the plugin from the input, and unbind any event listeners.
382
- ```js
383
- iti.destroy();
384
- ```
385
-
386
- **getExtension**
387
- Get the extension from the current number. Requires the [utils script to be loaded](#loading-the-utilities-script).
388
- ```js
389
- const extension = iti.getExtension();
390
- ```
391
- Returns a string, e.g. if the input value was `"(702) 555-5555 ext. 1234"`, this would return `"1234"`
392
-
393
- **getNumber**
394
- Get the current number in the given format (defaults to [E.164 standard](https://en.wikipedia.org/wiki/E.164)). The different formats are available in the enum `intlTelInput.utils.numberFormat` - which you can see [here](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L153). Requires the [utils script to be loaded](#loading-the-utilities-script). _Note that even if `nationalMode` is enabled, this can still return a full international number. Also note that this method expects a valid number, and so should only be used after validation._
395
- ```js
396
- const number = iti.getNumber();
397
- // or
398
- const number = iti.getNumber(intlTelInput.utils.numberFormat.E164);
399
- ```
400
- Returns a string e.g. `"+17024181234"`
401
-
402
- **getNumberType**
403
- Get the type (fixed-line/mobile/toll-free, etc) of the current number. Requires the [utils script to be loaded](#loading-the-utilities-script).
404
- ```js
405
- const numberType = iti.getNumberType();
406
- ```
407
- Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L162) in the enum `intlTelInput.utils.numberType`, e.g.
408
- ```js
409
- if (numberType === intlTelInput.utils.numberType.MOBILE) {
410
- // is a mobile number
411
- }
412
- ```
413
- _Note that in the US, there's no way to differentiate between fixed-line and mobile numbers, so instead it will return `FIXED_LINE_OR_MOBILE`._
414
-
415
- **getSelectedCountryData**
416
- Get the country data for the currently selected country.
417
- ```js
418
- const countryData = iti.getSelectedCountryData();
419
- ```
420
- Returns something like this:
421
- ```js
422
- {
423
- name: "Afghanistan",
424
- iso2: "af",
425
- dialCode: "93"
426
- }
427
- ```
428
-
429
- **getValidationError**
430
- Get more information about a validation error. Requires the [utils script to be loaded](#loading-the-utilities-script).
431
- ```js
432
- const error = iti.getValidationError();
433
- ```
434
- Returns an integer, which you can match against the [various options](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/utils.js#L178) in the enum `intlTelInput.utils.validationError`, e.g.
435
- ```js
436
- if (error === intlTelInput.utils.validationError.TOO_SHORT) {
437
- // the number is too short
438
- }
439
- ```
440
-
441
- **isValidNumber**
442
- (Note: only returns `true` for valid <ins>mobile numbers</ins> by default - see `allowedNumberTypes`)
443
- Check if the current number is valid based on its length - [see example](https://intl-tel-input.com/examples/validation-practical.html), which should be sufficient for most use cases. See `isValidNumberPrecise` (DANGEROUS) for more precise validation, but the advantage of `isValidNumber` is that it is much more future-proof, as while countries around the world regularly update their number rules, they rarely change their number lengths. If this method returns `false`, you can use `getValidationError` to get more information. Requires the [utils script to be loaded](#loading-the-utilities-script). _Note: previously named `isPossibleNumber`._
444
- ```js
445
- const isValid = iti.isValidNumber();
446
- ```
447
- Returns: `true`/`false`
448
-
449
- **isValidNumberPrecise** ⚠️ DANGEROUS
450
- (Note: only returns `true` for valid <ins>mobile numbers</ins> by default - see `allowedNumberTypes`)
451
- Check if the current number is valid using precise matching rules for each country/area code, etc - [see example](https://intl-tel-input.com/examples/validation.html). Note that these rules change each month for various countries around the world, so you need to constantly keep the plugin up-to-date (e.g. via an automated script) else <ins>you will start rejecting valid numbers</ins>. For a simpler and more future-proof form of validation, see `isValidNumber` above. If validation fails, you can use `getValidationError` to get more information. Requires the [utils script to be loaded](#loading-the-utilities-script).
452
- ```js
453
- const isValid = iti.isValidNumberPrecise();
454
- ```
455
- Returns: `true`/`false`
456
-
457
- **setCountry**
458
- Change the selected country. It should be rare, if ever, that you need to do this, as the selected country gets updated automatically when calling `setNumber` and passing a number including an international dial code, which is the recommended usage. Note, you can omit the country code argument to set the country to the default empty (globe) state. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number to either national or international format according to the `nationalMode` option._
459
- ```js
460
- iti.setCountry("gb");
461
- ```
462
-
463
- **setDisabled**
464
- Updates the disabled attribute of both the telephone input and the selected country button. Accepts a boolean value. _Note: we recommend using this instead of updating the disabled attribute of the input directly._
465
- ```js
466
- iti.setDisabled(true);
467
- ```
468
-
469
- **setNumber**
470
- Insert a number, and update the selected country accordingly. _Note that if `formatOnDisplay` is enabled, this will attempt to format the number to either national or international format according to the `nationalMode` option._
471
- ```js
472
- iti.setNumber("+447733123456");
473
- ```
474
-
475
- **setPlaceholderNumberType**
476
- Change the placeholderNumberType option.
477
- ```js
478
- iti.setPlaceholderNumberType("FIXED_LINE");
479
- ```
480
-
481
- ## Static Methods
482
-
483
- **getCountryData**
484
- Retrieve the plugin's country data - either to re-use elsewhere, e.g. to generate your own country dropdown - [see example](https://intl-tel-input.com/examples/country-sync.html), or alternatively, you could use it to modify the country data. Note that any modifications must be done before initialising the plugin.
485
- ```js
486
- const countryData = intlTelInput.getCountryData();
487
- ```
488
- Returns an array of country objects:
489
- ```js
490
- [{
491
- name: "Afghanistan",
492
- iso2: "af",
493
- dialCode: "93"
494
- }, ...]
495
- ```
496
-
497
- **getInstance**
498
- After initialising the plugin, you can always access the instance again using this method, by just passing in the relevant input element.
499
- ```js
500
- const input = document.querySelector('#phone');
501
- const iti = intlTelInput.getInstance(input);
502
- iti.isValidNumber(); // etc
503
- ```
504
-
505
- **attachUtils**
506
- An alternative to the `loadUtils` option, this method lets you manually load the utils.js script on demand, to enable formatting/validation etc. See [Loading The Utilities Script](#loading-the-utilities-script) for more information. This method should only be called once per page. A [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) object is returned so you can use `attachUtils().then(...)` to know when it's finished.
507
- ```js
508
- const loadUtils = () => import("/build/js/utils.js");
509
- intlTelInput.attachUtils(loadUtils);
510
- ```
511
-
512
- ## Events
513
- You can listen for the following events triggered on the input element.
514
-
515
- **countrychange**
516
- This is triggered when the selected country is updated, e.g. if the user selects a country from the dropdown, or they type a different dial code into the input, or you call `setCountry` etc.
517
- ```js
518
- input.addEventListener("countrychange", () => {
519
- // do something with iti.getSelectedCountryData()
520
- });
521
- ```
522
- See an example here: [Country sync](https://intl-tel-input.com/examples/country-sync.html)
523
-
524
- **open:countrydropdown**
525
- This is triggered when the user opens the dropdown.
526
-
527
- **close:countrydropdown**
528
- This is triggered when the user closes the dropdown.
529
-
530
- ## Theming / Dark Mode
531
- There are lots of CSS variables available for theming. See [intlTelInput.scss](https://github.com/jackocnr/intl-tel-input/blob/master/src/css/intlTelInput.scss) for the full list.
532
-
533
- Dark mode example (with screenshot below):
534
- ```css
535
- @media (prefers-color-scheme: dark) {
536
- .iti {
537
- --iti-border-color: #5b5b5b;
538
- --iti-dialcode-color: #999999;
539
- --iti-dropdown-bg: #0d1117;
540
- --iti-icon-color: #aaaaaa;
541
- --iti-hover-color: #30363d;
542
- }
543
- }
544
- ```
545
-
546
- NOTE: this assumes you already have your own dark mode styling in place for general body/input styling, e.g. something like this:
547
-
548
- ```css
549
- @media (prefers-color-scheme: dark) {
550
- body, input {
551
- color: white;
552
- background-color: #0d1117;
553
- }
554
- input {
555
- border-color: #5b5b5b;
556
- }
557
- input::placeholder {
558
- color: #8d96a0;
559
- }
560
- }
561
- ```
562
-
563
- Example:
564
- <img src="https://raw.github.com/jackocnr/intl-tel-input/master/screenshots/vanilla-dark.png" alt="Screenshot" width="263" height="269" />
565
-
566
- ## Utilities Script
567
- The utilities script ([src/js/utils.js](src/js/utils.js)) is a custom build of Google's [libphonenumber](https://github.com/googlei18n/libphonenumber) which enables the following features:
568
-
569
- * Formatting upon initialisation, as well as with `getNumber` and `setNumber`
570
- * Validation with `isValidNumber`, `getNumberType` and `getValidationError` methods
571
- * Placeholder set to an example number for the selected country - even specify the type of number (e.g. mobile) using the `placeholderNumberType` option
572
- * Extract the standardised (E.164) international number with `getNumber` even when using the `nationalMode` option
573
-
574
- International number formatting/validation is hard (it varies by country/district, and we currently support ~230 countries). The only comprehensive solution we have found is libphonenumber, from which we have precompiled the relevant parts into a single JavaScript file, included in the build directory. Unfortunately, even after modification, it is still ~260KB. See the section below on the best way to load it.
575
-
576
- ## Loading The Utilities Script
577
-
578
- The utils script provides lots of great functionality (see the above section), but comes at the cost of increased filesize (~260KB). There are two main ways to load the utils script, depending on whether you're concerned about filesize or not.
579
-
580
- **Option 1: intlTelInputWithUtils**
581
- If you're not concerned about filesize (e.g. you're lazy loading the main plugin script), the easiest thing to do is to use the full bundle (`/build/js/intlTelInputWithUtils.js`), which comes with the utils script included. This script can be used exactly like the main intlTelInput.js - so it can either be loaded directly onto the page (which defines `window.intlTelInput` like usual), or it can be imported like so: `import intlTelInput from "intl-tel-input/intlTelInputWithUtils"`.
582
-
583
- **Option 2: loadUtils**
584
- If you *are* concerned about filesize, you can lazy load the utils module when the plugin initialises, using the `loadUtils` initialisation option.
585
-
586
-
587
- ## Troubleshooting
588
-
589
- **Full-width input**
590
- If you want your input to be full-width, you need to set the container to be the same, i.e.
591
-
592
- ```css
593
- .iti { width: 100%; }
594
- ```
595
-
596
- **dropdownContainer: dropdown not closing on scroll**
597
- If you have a scrolling container other than `window` which is causing problems by not closing the dropdown on scroll, simply listen for the scroll event on that element, and trigger a scroll event on `window`, which in turn will close the dropdown, e.g.
598
-
599
- ```js
600
- scrollingElement.addEventListener("scroll", () => {
601
- const e = document.createEvent('Event');
602
- e.initEvent("scroll", true, true);
603
- window.dispatchEvent(e);
604
- });
605
- ```
606
-
607
- **Input margin**
608
- For the sake of alignment, the default CSS forces the input's vertical margin to `0px`. If you want a vertical margin, you should add it to the container (with class `iti`).
609
-
610
- **Displaying error messages**
611
- If your error handling code inserts an error message before the `<input>`, it will break the layout. Instead, you must insert it before the container (with class `iti`).
612
-
613
- **Dropdown position**
614
- The dropdown should automatically appear above/below the input depending on the available space. For this to work properly, you must only initialise the plugin after the `<input>` has been added to the DOM.
615
-
616
- **Placeholders**
617
- To get the automatic country-specific placeholder numbers, simply omit the placeholder attribute on the `<input>`, or set `autoPlaceholder` to `"aggressive"` to override any existing placeholder. Note: this requires the utils script to be loaded.
618
-
619
- **Bootstrap input groups**
620
- A couple of CSS fixes are required to get the plugin to play nice with Bootstrap [input groups](https://getbootstrap.com/docs/3.3/components/#input-groups). You can see a Codepen [here](https://codepen.io/jackocnr/pen/EyPXed).
621
- _Note: there is currently [a bug](https://bugs.webkit.org/show_bug.cgi?id=141822) in Mobile Safari which causes a crash when you click the dropdown arrow (a CSS triangle) inside an input group. The simplest workaround is to remove the CSS triangle with this line:_
622
-
623
- ```css
624
- .iti__arrow { border: none; }
625
- ```
626
-
627
49
  ## Contributing
628
50
  See the [contributing guide](https://github.com/jackocnr/intl-tel-input/blob/master/.github/CONTRIBUTING.md) for instructions on setting up the project and making changes, and also on how to update the flag images, or how to add a new translation.
629
51