🪄 Enhancement - Disable area code for specific country #96
-
SummaryIt would be beneficial to omit the area code for countries that do not use it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The area code is parsed anyway, so you can use the parsed value to convert to your desired format. Value{
"countryCode": 41,
"areaCode": "12",
"phoneNumber": "3456789",
"isoCode": "ch"
} Transformconst onChange = ({countryCode, areaCode, phoneNumber}) => {
const transformedValue = {countryCode, phoneNumber: `${areaCode}${phoneNumber}`};
console.log("transformedValue: ", transformedValue);
}
<PhoneInput
enableSearch
onChange={onChange}
/> |
Beta Was this translation helpful? Give feedback.
The example you have provided is achievable. It is enough to define a new country entity in the countries.json list that will use a different input mask for certain types of dial codes. The current list of country entities includes only the general masks and is based on Google's libphonenumber, which is checked for updates weekly. I recommend you to fork the react-phone-hooks, make your changes in the
countries.json
(use development application for testing the result) and open a pull-request. I will review and release the changes so you can use it for your needs. This is an example of one entity that makes it possible to have area codes of different lengths for the same country.[ "ch",