0

in the phone number text field if you want to give more than 12 digit 10 digit and 2 digit with a country code ,how to make it possible, because some country have 5-6 digit of country code so in that case they are not able to give the proper number. How to disable the restriction in react phone input 2.as for example if i want to give like phone number 919002007804567.how can I achieve in react phone input-2

import React, { useState } from "react";
import PhoneInput from "react-phone-input-2";
import "react-phone-input-2/lib/material.css";
export default function DropDown() {
  const [fields1, setFields1] = useState([{ value: null }]);
  function handleChange(i, event) {
    if (event) {
      let values = [...fields1];
      values[i].value = event;
      setFields1((v) => values);
    }
  }
  return (
    <div className="App">
        {fields1.map((field, idx) => (
      <PhoneInput
        country={"in"}
        key={idx}
        value={field.value || ""}
        onChange={(e) => handleChange(idx, e)}
      />
      ))}
    </div>
  );
}
Sougata Mukherjee
  • 547
  • 1
  • 8
  • 22
  • Which is the use case? Because this indicates that in total [telephone numbers shouldn't be larger than 15 digits](https://stackoverflow.com/questions/3350500/international-phone-number-max-and-min). – sebasaenz Apr 08 '22 at 13:07
  • use case is if user give invalid input i should provide some error msg for ,but here user are not able to give invalid phone number. How to enable the restrict condition in the input field so that user can give any digit like in normal text field – Sougata Mukherjee Apr 08 '22 at 13:12
  • ya but here i am not able to give 13/14/15 digit phone number in my input text field – Sougata Mukherjee Apr 08 '22 at 13:14
  • 1
    `react-phone-input-2` supports 4 digit area codes, check [Custom Area Codes](https://github.com/bl00mber/react-phone-input-2#custom-area-codes) and this [example](https://bl00mber.github.io/react-phone-input-2.html). – CS. Apr 08 '22 at 13:21
  • ya that right CS but there is no option like if user want to give 15 digit .its restricted the field – Sougata Mukherjee Apr 08 '22 at 13:33
  • 1
    On the [example page](https://bl00mber.github.io/react-phone-input-2.html), I could enter `186801234567890` in the first 2 input fields, it detected the country as Trinidad and Tobago! [Here is the source code for it](https://github.com/bl00mber/react-phone-input-2/blob/master/test/dev_js/demo.js). – CS. Apr 08 '22 at 13:46

0 Answers0