New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-phone-number-validation

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-phone-number-validation

`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

  • 1.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-64.29%
Maintainers
0
Weekly downloads
 
Created
Source

React Phone Number Validation

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.

Live Demo

To test React Phone Number Validation on CodeSandbox, click here.

Installation

You can install react-phone-number-validation via npm or yarn:

npm install react-phone-number-validation
# or
yarn add react-phone-number-validation

Usage

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;

Props

PropTypeDescriptionDefault
countryStringSet default country (e.g., 'gb' for United Kingdom).'af'
inputClassStringCustom class for the input element (optional).
dropdownClassStringCustom class for the dropdown element (optional).
autoSelectCountryBooleanAuto-select country based on user location (optional).false
enableSearchBooleanEnable country search (optional).false
disableDropdownBooleanDisable dropdown (optional).false
countryCodeEditableBooleanAllow user to edit country code (optional).true
hideAsteriskBooleanHide asterisk for required fields (optional).false
valueStringInput value (required).
setValueFunctionCallback function to update input value (required).
onChangeFunctionCallback function to handle input change (required).
dropdownStyleObjectCustom style for dropdown (optional).
searchPlaceholderStringSearch placeholder (optional).'Search'
nameStringInput name (optional).''
requiredBooleanRequired field (optional).false
searchNotFoundStringSearch not found message (optional).'No Country Found'
isValidMessageStringValidation message (optional).'Invalid Phone Number'
onRenderFunctionCallback function to handle render (optional).(value, country) => console.log(value, country)

Meta Dev Zone – @meta-dev-zone

Keywords

FAQs

Package last updated on 16 Oct 2024

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