Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-phone-input-2

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-phone-input-2

A react component to format phone numbers

  • 2.15.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
356K
increased by4.22%
Maintainers
1
Weekly downloads
 
Created

What is react-phone-input-2?

The react-phone-input-2 package is a React component for entering and validating international telephone numbers. It provides a user-friendly interface with country flags, auto-formatting, and validation features.

What are react-phone-input-2's main functionalities?

Basic Phone Input

This feature allows you to create a basic phone input field with a default country set to the United States. The phone number entered is logged to the console.

import React from 'react';
import PhoneInput from 'react-phone-input-2';
import 'react-phone-input-2/lib/style.css';

const App = () => {
  return (
    <PhoneInput
      country={'us'}
      value={''}
      onChange={phone => console.log(phone)}
    />
  );
};

export default App;

Custom Styles

This feature allows you to customize the styles of the phone input component, including the container, input field, and button.

import React from 'react';
import PhoneInput from 'react-phone-input-2';
import 'react-phone-input-2/lib/style.css';

const App = () => {
  return (
    <PhoneInput
      country={'us'}
      containerStyle={{ border: '1px solid red' }}
      inputStyle={{ width: '300px' }}
      buttonStyle={{ backgroundColor: 'blue' }}
    />
  );
};

export default App;

Country Dropdown

This feature enables a dropdown for selecting the country code, with an option to search for countries.

import React from 'react';
import PhoneInput from 'react-phone-input-2';
import 'react-phone-input-2/lib/style.css';

const App = () => {
  return (
    <PhoneInput
      country={'us'}
      enableSearch={true}
      disableDropdown={false}
    />
  );
};

export default App;

Localization

This feature allows you to localize the country names in the dropdown.

import React from 'react';
import PhoneInput from 'react-phone-input-2';
import 'react-phone-input-2/lib/style.css';

const App = () => {
  return (
    <PhoneInput
      country={'us'}
      localization={{ 'us': 'United States', 'gb': 'United Kingdom' }}
    />
  );
};

export default App;

Other packages similar to react-phone-input-2

Keywords

FAQs

Package last updated on 01 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc