
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
react-phone-number-validation
Advanced tools
`React Phone Number Validation` is a React component library that provides a customizable phone input field with a dropdown menu for selecting countries. This component simplifies the process of collecting phone numbers from users while allowing them to e
React Phone Number Validation is a React component library that provides a customizable phone input field with a dropdown menu for selecting countries. This component simplifies the process of collecting phone numbers from users while allowing them to easily choose their country code.
To test React Phone Number Validation on CodeSandbox, click here.
You can install react-phone-number-validation via npm or yarn:
npm install react-phone-number-validation
# or
yarn add react-phone-number-validation
Once installed, you can use the PhoneInput component in your React application:
import React, { useState } from "react";
import PhoneInput from "react-phone-number-validation";
const App = () => {
const [phoneNumber, setPhoneNumber] = useState("");
const handleChange = (value, country) => {
// Handle phone number change
console.log("Phone Number:", value);
console.log("Selected Country:", country);
setPhoneNumber(value);
};
return (
<PhoneInput
value={phoneNumber} // Current value of the phone number input (required)
setValue={setPhoneNumber} // Function to set the value of the phone number input (required)
onChange={handleChange} // Function called when the phone number changes (required)
/>
);
};
export default App;
| Prop | Type | Description | Default |
|---|---|---|---|
country | String | Set default country (e.g., 'gb' for United Kingdom). | 'af' |
inputClass | String | Custom class for the input element (optional). | |
dropdownClass | String | Custom class for the dropdown element (optional). | |
autoSelectCountry | Boolean | Auto-select country based on user location (optional). | false |
enableSearch | Boolean | Enable country search (optional). | false |
disableDropdown | Boolean | Disable dropdown (optional). | false |
countryCodeEditable | Boolean | Allow user to edit country code (optional). | true |
hideAsterisk | Boolean | Hide asterisk for required fields (optional). | false |
value | String | Input value (required). | |
setValue | Function | Callback function to update input value (required). | |
onChange | Function | Callback function to handle input change (required). | |
dropdownStyle | Object | Custom style for dropdown (optional). | |
searchPlaceholder | String | Search placeholder (optional). | 'Search' |
name | String | Input name (optional). | '' |
required | Boolean | Required field (optional). | false |
searchNotFound | String | Search not found message (optional). | 'No Country Found' |
isValidMessage | String | Validation message (optional). | 'Invalid Phone Number' |
onRender | Function | Callback function to handle render (optional). | (value, country) => console.log(value, country) |
Meta Dev Zone – @meta-dev-zone
FAQs
`React Phone Number Validation` is a React component library that provides a customizable phone input field with a dropdown menu for selecting countries. This component simplifies the process of collecting phone numbers from users while allowing them to e
We found that react-phone-number-validation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.