bl00mber / react-phone-input-2

:telephone_receiver: Highly customizable phone input component with auto formatting

Home Page:https://bl00mber.github.io/react-phone-input-2.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get selected country Code, like 'uk'

rijans opened this issue · comments

Any way to get selected country code? like 'uk' on select country?

Hi, You can destructure dialCode from data

interface IMaskedInput {
dialCode: string;
value: string;
}

const handlePhoneInputChange = (value: string, data: IMaskedInput) => {
console.log(data.dialCode); // +998
};

    <PhoneInput
    country={'uz'}
    autoFormat
    enableSearch
    countryCodeEditable={false}
    onChange={handlePhoneInputChange}
    inputProps={{
      name: PHONENUMBER,
    }}
  />