PHPackages                             simonschaufi/typo3-phone - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. simonschaufi/typo3-phone

ActiveTypo3-cms-extension[Validation &amp; Sanitization](/categories/validation)

simonschaufi/typo3-phone
========================

Adds phone number functionality to TYPO3 based on Google's libphonenumber API.

v4.0.0(12mo ago)465.3k↓18.1%2[3 PRs](https://github.com/simonschaufi/typo3-phone/pulls)GPL-2.0-or-laterPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0CI passing

Since Aug 3Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/simonschaufi/typo3-phone)[ Packagist](https://packagist.org/packages/simonschaufi/typo3-phone)[ Fund](https://www.paypal.me/simonschaufi/10)[ GitHub Sponsors](https://github.com/simonschaufi)[ RSS](/packages/simonschaufi-typo3-phone/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (24)Versions (25)Used By (0)

TYPO3 Phone
===========

[](#typo3-phone)

[![Donate](https://camo.githubusercontent.com/b57c445af971e3e99c2d0ccdbf4fa7faa4358ba27fecc8f68459b30289f82eda/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d626c75652e737667)](https://www.paypal.me/simonschaufi/20)[![GitHub Sponsors](https://camo.githubusercontent.com/acb293cadb468c7c3d2f5da9bfdb8a12476d4ee5428c198a5915f8a34720cd3a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f73696d6f6e736368617566693f6c6162656c3d47697448756225323053706f6e736f7273)](https://github.com/sponsors/simonschaufi)[![Buy me a coffee](https://camo.githubusercontent.com/d1150deebf888c0ddc228dfc39fdc9553b4eeb3996b8364287e960d8f95c7e5a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4275795f6d655f615f636f666665652d677261793f6c6f676f3d6275796d6561636f66666565)](https://www.buymeacoffee.com/simonschaufi)[![CI](https://github.com/simonschaufi/typo3-phone/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/simonschaufi/typo3-phone/actions/workflows/ci.yml)[![Latest Stable Version](https://camo.githubusercontent.com/6d57d7934490bbee7b79cb4fc5fdfa1b818643ea6cb5979106084e923816d02e/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e736368617566692f7479706f332d70686f6e652f762f737461626c65)](https://packagist.org/packages/simonschaufi/typo3-phone)[![Total Downloads](https://camo.githubusercontent.com/d5fa00a10f7a524c830c161947dfacce96b20f12fbd794d6ce72a6ee436e340b/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e736368617566692f7479706f332d70686f6e652f646f776e6c6f616473)](https://packagist.org/packages/simonschaufi/typo3-phone)[![License](https://camo.githubusercontent.com/ea214b9b7e0c8a093c6a354f1debbc5aee0312ffe0aefca1a901ff55df499c9a/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e736368617566692f7479706f332d70686f6e652f6c6963656e7365)](https://packagist.org/packages/simonschaufi/typo3-phone)[![TYPO3](https://camo.githubusercontent.com/2cf6570821614808899422f68a66a381a2de1dd0746ba9cdba6155def1f4f396/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5459504f332d31332d6f72616e67652e737667)](https://get.typo3.org/version/13)

Adds phone number functionality to TYPO3 based on the [PHP port](https://github.com/giggsey/libphonenumber-for-php)of [libphonenumber by Google](https://github.com/googlei18n/libphonenumber).

Installation
------------

[](#installation)

Run the following command to install the latest applicable version of the package:

```
composer require simonschaufi/typo3-phone
```

Validation
----------

[](#validation)

For each action (here `updateAction`) you want to validate your object (in this case an Address with two properties "phone" and "fax") add the following code in your controller:

```
use SimonSchaufi\TYPO3Phone\Validation\Validator\PhoneValidator;

public function initializeUpdateAction(): void
{
	if ($this->request->hasArgument('address') && $this->request->getArgument('address')) {
		$addressValidator = $this->validatorResolver->getBaseValidatorConjunction(Address::class);

		$validators = $addressValidator->getValidators();
		$validators->rewind();
		$validator = $validators->current();

		/** @var PhoneValidator $phoneValidator */
		$phoneValidator = $this->validatorResolver->createValidator(PhoneValidator::class, [
			// If the user enters a number prefixed with "+" then the country can be guessed.
			// If not, the following countries listed in the array will be checked against
			'countries' => ['DE'],
			'international' => true,
		]);

		$validator->addPropertyValidator('phone', $phoneValidator);
		$validator->addPropertyValidator('fax', $phoneValidator);
	}
}
```

Alternatively you can instantiate the validator anywhere in your code like this:

```
use SimonSchaufi\TYPO3Phone\Validation\Validator\PhoneValidator;

$phoneValidator = GeneralUtility::makeInstance(PhoneValidator::class);
$phoneValidator->setOptions([
	// If the user enters a number prefixed with "+" then the country can be guessed.
	// If not, the following countries listed in the array will be checked against
	'countries' => ['DE'],
	'types' => ['mobile'],
	'international' => true,
]);

$result = $phoneValidator->validate('+3212345678');

if ($result->hasErrors()) {
	// Error handling
}
```

Note: country codes should be [*ISO 3166-1 alpha-2 compliant*](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).

To support *any valid internationally formatted* phone number next to the whitelisted countries, use the `international` option. This can be useful when you're expecting locally formatted numbers from a specific country but also want to accept any other foreign number entered properly:

```
$phoneValidator->setOptions([
    'international' => true,
]);
```

The validator will try to extract the country from the number itself and then check if the number is valid for that country. If the country could not be guessed it will be validated using the fallback countries if provided. Note that country guessing will only work when phone numbers are entered in *international format* (prefixed with a `+` sign, e.g. +32 ....). Leading double zeros will **NOT** be parsed correctly as this isn't an established consistency.

To specify constraints on the number type, set the allowed types, e.g.:

```
$phoneValidator->setOptions([
    'types' => ['mobile'],
]);
```

The most common types are `mobile` and `fixed_line`, but feel free to use any of the types defined [here](https://github.com/giggsey/libphonenumber-for-php/blob/master/src/PhoneNumberType.php).

You can also enable lenient validation by using the `lenient` option. With leniency enabled, only the length of the number is checked instead of actual carrier patterns.

```
$phoneValidator->setOptions([
    'lenient' => true,
]);
```

### Validation outside of Extbase

[](#validation-outside-of-extbase)

If you **don't** want to use the extbase validator and instead a more low level approach, use the following code:

Info: In this case the Address object has a property "country" that is of type `\SJBR\StaticInfoTables\Domain\Model\Country`

```
use SimonSchaufi\TYPO3Phone\Exceptions\NumberParseException;
use SimonSchaufi\TYPO3Phone\PhoneNumber;

if (!empty($address->getPhone())) {
	try {
		$phoneNumber = (new PhoneNumber($address->getPhone(), [$address->getCountry()->getIsoCodeA2()]))->formatInternational();
		$address->setPhone($phoneNumber);
	} catch (NumberParseException $exception) {
		// Error handling
	}
}
```

Utility PhoneNumber class
-------------------------

[](#utility-phonenumber-class)

A phone number can be wrapped in the `SimonSchaufi\TYPO3Phone\PhoneNumber` class to enhance it with useful utility methods. It's safe to directly reference these objects in views or when saving to the database as they will degrade gracefully to the E.164 format.

```
use SimonSchaufi\TYPO3Phone\PhoneNumber;

(string) new PhoneNumber('+3212/34.56.78');     // +3212345678
(string) new PhoneNumber('012 34 56 78', 'BE'); // +3212345678
```

### Formatting

[](#formatting)

A PhoneNumber can be formatted in various ways:

```
use SimonSchaufi\TYPO3Phone\PhoneNumber;

$phone = new PhoneNumber('012/34.56.78', 'BE');

$phone->format($format);       // See libphonenumber\PhoneNumberFormat
$phone->formatE164();          // +3212345678
$phone->formatInternational(); // +32 12 34 56 78
$phone->formatRFC3966();       // +32-12-34-56-78
$phone->formatNational();      // 012 34 56 78

// Formats so the number can be called straight from the provided country.
$phone->formatForCountry('BE'); // 012 34 56 78
$phone->formatForCountry('NL'); // 00 32 12 34 56 78
$phone->formatForCountry('US'); // 011 32 12 34 56 78

// Formats so the number can be clicked on and called straight from the provided country using a cellphone.
$phone->formatForMobileDialingInCountry('BE'); // 012345678
$phone->formatForMobileDialingInCountry('NL'); // +3212345678
$phone->formatForMobileDialingInCountry('US'); // +3212345678
```

### Number information

[](#number-information)

Get some information about the phone number:

```
use SimonSchaufi\TYPO3Phone\PhoneNumber;

$phone = new PhoneNumber('012 34 56 78', 'BE');

$phone->getType();              // 'fixed_line'
$phone->isOfType('fixed_line'); // true
$phone->getCountry();           // 'BE'
$phone->isOfCountry('BE');      // true
```

### Equality comparison

[](#equality-comparison)

Check if a given phone number is (not) equal to another one:

```
use SimonSchaufi\TYPO3Phone\PhoneNumber;

$phone = new PhoneNumber('012 34 56 78', 'BE');

$phone->equals('012/34.56.78', 'BE')       // true
$phone->equals('+32 12 34 56 78')          // true
$phone->equals($anotherPhoneObject)        // true/false

$phone->notEquals('045 67 89 10', 'BE')    // true
$phone->notEquals('+32 45 67 89 10')       // true
$phone->notEquals($anotherPhoneObject)     // true/false
```

Database considerations
-----------------------

[](#database-considerations)

> Disclaimer: Phone number handling is quite different in each application. The topics mentioned below are therefore meant as a set of thought starters; support will **not** be provided.

Storing phone numbers in a database has always been a speculative topic and there's simply no silver bullet. It all depends on your application's requirements. Here are some things to take into account, along with an implementation suggestion. Your ideal database setup will probably be a combination of some of the pointers detailed below.

### Uniqueness

[](#uniqueness)

The E.164 format globally and uniquely identifies a phone number across the world. It also inherently implies a specific country and can be supplied as-is to the `phone()` helper.

You'll need:

- One column to store the phone number
- To format the phone number to E.164 before persisting it

Example:

- User input = `012/45.65.78`
- Database column
    - `phone` (varchar) = `+3212456578`

### Presenting the phone number the way it was inputted

[](#presenting-the-phone-number-the-way-it-was-inputted)

If you store formatted phone numbers the raw user input will irretrievably get lost. It may be beneficial to present your users with their very own inputted phone number, for example in terms of improved user experience.

You'll need:

- Two columns to store the raw input and the correlated country

Example:

- User input = `012/34.56.78`
- Database columns
    - `phone` (varchar) = `012/34.56.78`
    - `phone_country` (varchar) = `BE`

### Supporting searches

[](#supporting-searches)

Searching through phone numbers can quickly become ridiculously complex and will always require deep understanding of the context and extent of your application. Here's *a* possible approach covering quite a lot of "natural" use cases.

You'll need:

- Three additional columns to store searchable variants of the phone number:
    - Normalized input (raw input with all non-alpha characters stripped)
    - National formatted phone number (with all non-alpha characters stripped)
    - E.164 formatted phone number
- An extensive search query utilizing the searchable variants

Example:

- User input = `12/34.56.78`
- Database columns
    - `phone_normalized` (varchar) = `12345678`
    - `phone_national` (varchar) = `012345678`
    - `phone_e164` (varchar) = `+3212345678`

Need help with integrating this extension into your website?
------------------------------------------------------------

[](#need-help-with-integrating-this-extension-into-your-website)

Please contact me via my website:  and I will help you!

Giving thanks
-------------

[](#giving-thanks)

This extension is heavily inspired by . Thank you!

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance72

Regular maintenance activity

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 70.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Recently: every ~99 days

Total

16

Last Release

361d ago

Major Versions

v1.3.0 → v2.0.02022-03-16

v2.0.2 → v3.0.02024-01-16

v2.1.0 → v3.1.12024-04-23

v2.1.1 → 11.x-dev2024-04-24

v2.1.3 → v4.0.02025-05-23

PHP version history (5 changes)v1.0.0PHP ^7.1

v1.1.0PHP ^7.2

v2.0.0PHP ^7.4 || ^8.0

v3.0.0PHP ^8.1

v4.0.0PHP ~8.2.0 || ~8.3.0 || ~8.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/851921f03d132288119a99dba83e85abc620f3f896f8baaf1e5d107955064dfa?d=identicon)[simonschaufi](/maintainers/simonschaufi)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (190 commits)")[![simonschaufi](https://avatars.githubusercontent.com/u/941794?v=4)](https://github.com/simonschaufi "simonschaufi (81 commits)")

---

Tags

libphonenumberphonephone-numberphonenumbertypo3typo3-cms-extensiontypo3-phonevalidationvalidation-libraryvalidatorvalidationphonelibphonenumbertypo3

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/simonschaufi-typo3-phone/health.svg)

```
[![Health](https://phpackages.com/badges/simonschaufi-typo3-phone/health.svg)](https://phpackages.com/packages/simonschaufi-typo3-phone)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k148.7M416](/packages/giggsey-libphonenumber-for-php)[giggsey/libphonenumber-for-php-lite

A lite version of giggsey/libphonenumber-for-php, which is a PHP Port of Google's libphonenumber

8912.9M47](/packages/giggsey-libphonenumber-for-php-lite)[borales/yii2-phone-input

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

1341.6M6](/packages/borales-yii2-phone-input)[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.3k](/packages/stuyam-laravel-phone-validator)[ellisio/laravel-phone

A phone validator for Laravel using the free Twilio phone lookup service.

1130.0k](/packages/ellisio-laravel-phone)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
