1.2.0 • Published 8 months ago

react-phone-number-validation v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

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

1.2.0

8 months ago

1.1.1

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.0

11 months ago

1.0.8

11 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago