twenty/packages/twenty-shared/src/utils/validation/phones-value/getCountryCodesForCallingCode.ts
Etienne e8905be71a
Import - Improve phone validation (#12901)
Context : 
- Phones import is a bit complex if not all subfields are provided.
- Phones subfield validation are absent or different from BE validation.

Solution : 
- Normalize callingCode and countryCode validation (BE/FE)
- Ease phone import if only phoneNumber is provided
2025-07-04 23:07:24 +02:00

15 lines
467 B
TypeScript

import { getCountries, getCountryCallingCode } from 'libphonenumber-js';
const ALL_COUNTRIES_CODE = getCountries();
export const getCountryCodesForCallingCode = (callingCode: string) => {
const cleanCallingCode = callingCode.startsWith('+')
? callingCode.slice(1)
: callingCode;
return ALL_COUNTRIES_CODE.filter((country) => {
const countryCallingCode = getCountryCallingCode(country);
return countryCallingCode === cleanCallingCode;
});
};