Display a Phone Number field which use the Intl Tel Input library.
Setting name | Description |
Allow Countries | Filter which countries can be chosen |
Preferred Countries | Define the countries to appear at the top of the list |
Default Country | Set the initial country selection |
Geolocation | Lookup the user’s country based on their IP address |
Native Names | Show native country names |
National Mode | Allow users to enter national numbers |
Allow Dropdown | Whether or not to allow the dropdown |
Separate Dial Code | Display the country dial code next to the selected flag |
Default Value | Must be international number with prefix. ie: +1201-555-0123 |
Placeholder | You may use {placeholder} to print the country phone number placeholder |
Return Value | Return the phone number array or the phone number |
$phone_number = get_field('phone_number');
// +12015550123
$phone_number = get_field('phone_number');
/**
* array(
* 'number' => '+12015550123',
* 'country' => 'us',
* 'national' => '+12015550123',
* 'international' => '+12015550123',
* )
*/
$phone_number = get_field('phone_number');
/**
* array(
* 'number' => '+12015550123',
* 'country' => 'us',
* 'national' => '(201) 555-0123',
* 'international' => '+1 201-555-0123',
* )
*/
$phone_number = get_field('phone_number');
// (201) 555-0123
$phone_number = get_field('phone_number');
// +1 201-555-0123
$phone_number = get_field('phone_number', false, false);
// +12015550123
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.