Convert Figma logo to code with AI

jackocnr logointl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React, Vue and Angular components also included.

8,152
1,996
8,152
5

Top Related Projects

:telephone_receiver: Highly customizable phone input component with auto formatting

14,148

Cross-browser QRCode generator for javascript

Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers.

PHP version of Google's phone number handling library

Google's common JavaScript library

Quick Overview

intl-tel-input is a JavaScript plugin for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods.

Pros

  • Easy integration with existing forms and input fields
  • Automatic country detection based on user's IP address
  • Extensive customization options and styling flexibility
  • Comprehensive validation and formatting features

Cons

  • May increase page load time due to additional resources
  • Requires maintenance to keep country codes and formatting rules up-to-date
  • Can be overkill for simple forms or applications with limited international scope

Code Examples

  1. Basic initialization:
const input = document.querySelector("#phone");
window.intlTelInput(input, {
  utilsScript: "path/to/utils.js"
});
  1. Getting the full international number:
const iti = window.intlTelInput(input);
const number = iti.getNumber();
console.log(number); // e.g. "+1 (702) 123-4567"
  1. Custom country prioritization:
window.intlTelInput(input, {
  preferredCountries: ['us', 'gb', 'ca']
});
  1. Validation on form submission:
form.addEventListener('submit', function(e) {
  e.preventDefault();
  if (iti.isValidNumber()) {
    console.log("Valid number: " + iti.getNumber());
  } else {
    console.log("Invalid number");
  }
});

Getting Started

  1. Include the CSS and JavaScript files in your HTML:
<link rel="stylesheet" href="path/to/intlTelInput.css">
<script src="path/to/intlTelInput.min.js"></script>
  1. Add an input element to your HTML:
<input id="phone" type="tel">
  1. Initialize the plugin:
const input = document.querySelector("#phone");
window.intlTelInput(input, {
  utilsScript: "path/to/utils.js"
});
  1. (Optional) Handle the validation on form submission:
form.addEventListener('submit', function(e) {
  e.preventDefault();
  if (iti.isValidNumber()) {
    // Process the valid number
  } else {
    // Show error message
  }
});

Competitor Comparisons

:telephone_receiver: Highly customizable phone input component with auto formatting

Pros of react-phone-input-2

  • Built specifically for React, offering better integration with React applications
  • Provides more customization options out of the box
  • Includes additional features like auto-formatting and country guessing

Cons of react-phone-input-2

  • Less widely adopted compared to intl-tel-input
  • May have a steeper learning curve for developers not familiar with React
  • Smaller community and potentially fewer resources for troubleshooting

Code Comparison

intl-tel-input:

$("#phone").intlTelInput({
  utilsScript: "path/to/utils.js"
});

react-phone-input-2:

import PhoneInput from 'react-phone-input-2'

<PhoneInput
  country={'us'}
  value={this.state.phone}
  onChange={phone => this.setState({ phone })}
/>

The code comparison shows that intl-tel-input uses jQuery for initialization, while react-phone-input-2 is a React component that can be easily integrated into React applications. The react-phone-input-2 example demonstrates how state management is handled within the component, which is more aligned with React's paradigm.

Both libraries offer similar core functionality for international phone number input, but their implementation and usage differ based on the target environment and framework preferences.

14,148

Cross-browser QRCode generator for javascript

Pros of qrcodejs

  • Lightweight and focused solely on QR code generation
  • No external dependencies, making it easy to integrate
  • Supports various output formats (canvas, table, SVG)

Cons of qrcodejs

  • Less actively maintained compared to intl-tel-input
  • Limited functionality beyond QR code generation
  • Lacks built-in styling options for customization

Code Comparison

qrcodejs:

var qrcode = new QRCode("qrcode", {
    text: "https://example.com",
    width: 128,
    height: 128
});

intl-tel-input:

var input = document.querySelector("#phone");
window.intlTelInput(input, {
    utilsScript: "path/to/utils.js"
});

While qrcodejs focuses on generating QR codes with minimal setup, intl-tel-input provides a more comprehensive solution for handling international phone numbers with additional features and customization options. The code examples demonstrate the simplicity of qrcodejs for QR code generation compared to the more complex setup required for intl-tel-input's phone number input functionality.

Google's common Java, C++ and JavaScript library for parsing, formatting, and validating international phone numbers.

Pros of libphonenumber

  • More comprehensive phone number parsing and validation
  • Supports a wider range of countries and formats
  • Regularly updated with new phone number patterns and metadata

Cons of libphonenumber

  • Larger library size, which may impact load times
  • More complex implementation, requiring additional setup
  • Less focus on UI components, primarily a backend library

Code Comparison

intl-tel-input:

$("#phone").intlTelInput({
  utilsScript: "path/to/utils.js",
  preferredCountries: ["us", "gb"]
});

libphonenumber:

const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();
const number = phoneUtil.parse('+1 650-253-0000', 'US');
console.log(phoneUtil.isValidNumber(number));

Summary

intl-tel-input is a lightweight, user-friendly library focused on providing an interactive phone input UI component. It's easier to implement and offers a visually appealing interface out of the box.

libphonenumber, on the other hand, is a more robust and comprehensive solution for phone number parsing, validation, and formatting. It's better suited for complex backend operations and supports a wider range of countries and formats.

Choose intl-tel-input for simple, frontend-focused projects, and libphonenumber for more extensive, backend-heavy applications requiring advanced phone number handling.

PHP version of Google's phone number handling library

Pros of libphonenumber-for-php

  • More comprehensive phone number parsing and validation capabilities
  • Based on Google's libphonenumber library, ensuring high accuracy and regular updates
  • Supports a wider range of phone number-related operations (e.g., formatting, carrier lookup)

Cons of libphonenumber-for-php

  • Requires server-side processing, which may increase server load
  • Lacks built-in UI components for phone number input
  • More complex implementation compared to client-side solutions

Code Comparison

libphonenumber-for-php:

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$phoneNumber = $phoneUtil->parse($number, $countryCode);
$isValid = $phoneUtil->isValidNumber($phoneNumber);

intl-tel-input:

var input = document.querySelector("#phone");
var iti = window.intlTelInput(input);
var isValid = iti.isValidNumber();

Key Differences

  • libphonenumber-for-php is a server-side PHP library, while intl-tel-input is a client-side JavaScript plugin
  • intl-tel-input provides a user-friendly interface for phone number input, including country selection
  • libphonenumber-for-php offers more advanced phone number manipulation and analysis features
  • intl-tel-input is easier to implement for basic phone number validation in web forms
  • libphonenumber-for-php is better suited for applications requiring extensive phone number processing and analysis

Both libraries have their strengths and are suitable for different use cases, depending on the specific requirements of the project.

Google's common JavaScript library

Pros of closure-library

  • Comprehensive JavaScript library with a wide range of utilities and components
  • Robust and well-tested, used in large-scale Google applications
  • Supports modular development and code optimization

Cons of closure-library

  • Steeper learning curve due to its size and complexity
  • May be overkill for smaller projects or specific use cases
  • Less focused on internationalization features compared to intl-tel-input

Code Comparison

intl-tel-input:

var input = document.querySelector("#phone");
window.intlTelInput(input, {
  utilsScript: "path/to/utils.js"
});

closure-library:

goog.require('goog.dom');
goog.require('goog.ui.InputDatePicker');

var datePickerInput = new goog.ui.InputDatePicker();
datePickerInput.render(goog.dom.getElement('datepicker'));

Summary

While closure-library offers a comprehensive set of tools for large-scale JavaScript applications, intl-tel-input is more focused on providing a specific solution for international telephone input fields. closure-library's breadth of features comes at the cost of increased complexity, while intl-tel-input offers a simpler, more targeted approach for its specific use case.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

International Telephone Input CI version downloads

A JavaScript plugin for entering, formatting and validating international telephone numbers. React, Vue, Angular and Svelte components also included.

Explore docs »

Plugin screenshot showing country dropdown open

Sponsored by

Twilio

Use Twilio's API to build phone verification, SMS 2FA, appointment reminders, marketing notifications and so much more. We can't wait to see what you build.

React, Vue, Angular and Svelte Components

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, the Vue Component the Angular Component, or the Svelte component (beta).

Docs and Examples

We have a newly updated website, where you can find a full set of docs, a live playground where you can try out all of the options, as well as plenty of examples of different setups.

Features

  • Automatically select the user's current country using an IP lookup
  • Automatically set the input placeholder to an example number for the selected country
  • Navigate the country dropdown by typing a country's name, or using the up/down keys
  • Automatically format the number as the user types
  • Optionally, only allow numeric characters and cap the number at the maximum valid length
  • The user types their national number, and the plugin gives you the full standardised international number
  • Number validation, including specific error types
  • High-resolution flag images
  • Accessibility provided via ARIA tags
  • Typescript type definitions included
  • Easily customise styles by overriding CSS variables, e.g. support dark mode
  • React, Vue, Angular and Svelte components also included
  • Translations provided in over 40 languages, as well as support for RTL layout and alternative numeral sets
  • Lots of initialisation options for customisation, as well as instance methods/events for interaction

Contributing

See the contributing guide 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.

Attributions

User testing powered by BrowserStack Open-Source Program

Browser testing via

NPM DownloadsLast 30 Days