intl-tel-input
repository·master·Indexed 27 days ago
https://github.com/jackocnr/intl-tel-inputA comprehensive library for entering, formatting, and validating international telephone numbers. It features a user interface for country selection via name or dial code and supports auto-detecting the user's country. Available as a vanilla JavaScript library and as official framework wrappers for React (@intl-tel-input/react), Vue (@intl-tel-input/vue), Angular, and Svelte (@intl-tel-input/svelte).
What's inside intl-tel-input
- intl-tel-input is a library for entering, formatting, and validating international telephone numbers. It provides a user interface for fast country picking (via name or dial code) and supports auto-detecting the user's country. It is available as a vanilla JavaScript library or as dedicated components for React, Vue, Angular, and Svelte.
Choose your intl-tel-input integration
masterYou can integrate
intl-tel-inputinto your project using either the vanilla JavaScript library or dedicated framework components. Both options use the same core engine providing country selection, formatting, and validation.Vanilla JavaScript library
Use this if you are not using a frontend framework or prefer to manage the DOM manually. It is lightweight and has zero dependencies.
Framework components
Use these if you are using React, Vue, Angular, or Svelte. The components automate lifecycle management, two-way data binding, and provide typed change callbacks.
Install and use @intl-tel-input/react
masterThe@intl-tel-input/reactpackage provides a React component for entering, formatting, and validating international telephone numbers. For full documentation, a live playground to test options, and various setup examples, visit the official intl-tel-input website.Install and use the intl-tel-input Vue component
masterThe@intl-tel-input/vuepackage provides a Vue component for entering, formatting, and validating international telephone numbers. For detailed configuration options and API usage, refer to the official documentation.Install and use the intl-tel-input Svelte component
masterThe@intl-tel-input/sveltepackage provides a Svelte component for entering, formatting, and validating international telephone numbers. For full documentation, a live playground to test options, and specific implementation examples (such as validation setups), visit the official intl-tel-input documentation.Support Right-to-left (RTL) languages
masterThe library automatically supports RTL layouts if the
dir="rtl"attribute is set on the<html>element or any of its ancestors.Note that while the layout flows right-to-left, phone numbers and dial codes are displayed left-to-right to follow standard telephone number formatting.
Install and setup the @intl-tel-input/vue component
masterTo use the
intl-tel-inputcomponent in a Vue application, install the package via npm and import both the component and its required styles.To avoid bloating your initial bundle, it is recommended to load the
utilsscript (approx. 260KB) using a dynamic import via theload-utilsprop. Alternatively, you can import from@intl-tel-input/vue/with-utilsto bundle the utils directly if the component itself is already being lazy-loaded.npm install @intl-tel-input/vue<script setup> import IntlTelInput from "@intl-tel-input/vue"; import "intl-tel-input/styles"; </script> <template> <IntlTelInput initial-country="us" :load-utils="() => import('intl-tel-input/utils')" /> </template>Install intl-tel-input using a bundler
masterTo use the library with a modern bundler like Vite or Webpack, install the package via npm and import both the JavaScript and CSS. It is recommended to use the
loadUtilsoption with a dynamic import to lazy-load the utils script (~260KB) so it doesn't increase your initial bundle size.npm install intl-tel-inputimport intlTelInput from "intl-tel-input"; import "intl-tel-input/styles"; const input = document.querySelector("#phone"); intlTelInput(input, { loadUtils: () => import("intl-tel-input/utils"), });Install intl-tel-input using a script tag
masterFor a quick start without a build step, load the CSS and the minified JavaScript directly from a CDN like jsDelivr. You must also provide a
loadUtilsfunction to handle the utility script required for formatting and validation.<!-- Add the CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@29.1.2/dist/css/intlTelInput.css"> <!-- Add the script and initialise --> <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@29.1.2/dist/js/intlTelInput.min.js"></script> <script> const input = document.querySelector("#phone"); window.intlTelInput(input, { loadUtils: () => import("https://cdn.jsdelivr.net/npm/intl-tel-input@29.1.2/dist/js/utils.js"), }); </script>Install and set up the @intl-tel-input/svelte component
masterTo use the
intl-tel-inputcomponent in a Svelte 5 project, install the package via npm and import both the component and the required styles.It is recommended to use a dynamic import for
loadUtilsto ensure the ~260KB utils script is lazy-loaded and doesn't bloat your initial bundle. Alternatively, you can import from@intl-tel-input/svelte/with-utilsto bundle the utils directly with the component.npm install @intl-tel-input/svelte<script> import IntlTelInput from "@intl-tel-input/svelte"; import "intl-tel-input/styles"; </script> <IntlTelInput initialCountry="us" loadUtils={() => import("intl-tel-input/utils")} />Determine if the utils script is required
masterThe
utilsscript is required if you want to use advanced features such as:- Formatting and validation helpers
- Automatic country-specific placeholders
If you only need basic flag selection and input, you can omit it.
Build and run the intl-tel-input website locally
masterTo run the documentation website locally for development or testing, follow these steps:
- Install dependencies: Run
npm installin the root of theintl-tel-inputproject. - Build the site: Navigate to the
site/directory and runnpm run build. - Serve the site: Navigate to the
site/dist/directory and start a web server (e.g., usinghttp-server).
If you do not have
http-serverinstalled, you can install it globally vianpm install -g http-server.- Install dependencies: Run