Field Render

Display a Phone Number field which use the Intl Tel Input library.

Field Group

Field Settings

Setting nameDescription
Allow CountriesFilter which countries can be chosen
Preferred CountriesDefine the countries to appear at the top of the list
Default CountrySet the initial country selection
GeolocationLookup the user’s country based on their IP address
Native NamesShow native country names
National ModeAllow users to enter national numbers
Allow DropdownWhether or not to allow the dropdown
Separate Dial CodeDisplay the country dial code next to the selected flag
Default ValueMust be international number with prefix. ie: +1201-555-0123
PlaceholderYou may use {placeholder} to print the country phone number placeholder
Return ValueReturn the phone number array or the phone number

Field Value

Value can then be retrieved using the common get_field() function. Usage example:

$slug = get_field('phone_number');

// +1201-555-0123

Field Format

Using the the libphonenumber for PHP library, it is possible to format a phone number to national format (044 668 18 00) or international format (+41 44 668 18 00). You can use the ACF Extended libphonenumber for PHP addon in order to easily access to that library. See Field Validation section for more details.

Here is a usage example:

// +33612457854
$phone_number = get_field('phone_number');

// retrieve library
$phone_library = \libphonenumber\PhoneNumberUtil::getInstance();

// parse phone number
$phone_data = $phone_library->parse($phone_number);

// 06 12 45 78 54
$phone_library->format($phone_data, \libphonenumber\PhoneNumberFormat::NATIONAL);

// +33 6 12 45 78 54
$phone_library->format($phone_data, \libphonenumber\PhoneNumberFormat::INTERNATIONAL);

You’ll find more usage examples in the library Github page.

Field Validation

By default the field is bundled with a Javascript validation method which use the builtin libphonenumber library included in Intl Tel Input.

While this method work in 95% of the case, some users may bypass that validation by disabling their browser Javascript. In order to validate the field from the server, and make sure the phone is always validated, we recommend to include the libphonenumber for PHP library.

We decided to not include that library by default, as it weighs more than 10MB and we want to keep ACF Extended as much lightweight as possible. You can easily include that library using the ACF Extended libphonenumber for PHP addon. Once activated, the field will automatically use the server validation from the library.