PHPackages                             carono/yii2-phone-helper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. carono/yii2-phone-helper

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

carono/yii2-phone-helper
========================

A helper for clearing a phone number and forming a string by mask

1.0.1(9mo ago)03MITPHPPHP ^7.4 || 8.\*

Since Jul 31Pushed 9mo agoCompare

[ Source](https://github.com/carono/yii2-phone-helper)[ Packagist](https://packagist.org/packages/carono/yii2-phone-helper)[ RSS](/packages/carono-yii2-phone-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Yii2 Phone Helper
=================

[](#yii2-phone-helper)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://opensource.org/licenses/MIT)[![Yii2](https://camo.githubusercontent.com/baecb505f47d61d55742f4818c36d0f857adff3454d7fecf2829f30ca0ffddde/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5969692d322e782d677265656e2e737667)](https://www.yiiframework.com/)

A Yii2 extension that provides helper functions for phone number processing, including normalization, validation, and formatting.

Features
--------

[](#features)

- Phone number normalization (removing all non-digit characters)
- Phone number validation against country codes
- Formatting phone numbers according to masks
- Built-in validator for Yii2 models
- Comprehensive country code database included

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require carono/yii2-phone-helper

```

or add

```
"carono/yii2-phone-helper": "*"
```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Basic Phone Number Processing

[](#basic-phone-number-processing)

```
use carono\yii2\helpers\PhoneHelper;

// Clear phone number from non-digit characters
$cleanNumber = PhoneHelper::clear('+7 (123) 456-78-90'); // returns '71234567890'

// Normalize phone number (returns null if number doesn't match any known country code)
$normalized = PhoneHelper::normalNumber('+7 (123) 456-78-90'); // returns '71234567890'

// Format phone number according to its country code mask
$formatted = PhoneHelper::asString('71234567890'); // returns '+7 (123) 456-78-90' for Russian numbers
```

### Using in Yii2 Models

[](#using-in-yii2-models)

```
use carono\yii2\helpers\PhoneFilter;

public function rules()
{
    return [
        [['phone'], PhoneFilter::class],
        // or with custom validation
        [['phone'], 'filter', 'filter' => [PhoneHelper::class, 'normalNumber']],
    ];
}
```

### Getting Country Code Information

[](#getting-country-code-information)

```
$codeInfo = PhoneHelper::getCode('71234567890');
/*
Returns array like:
{
	"mask": "+7(###)###-##-##",
	"cc": "RU",
	"name_en": "Russia",
	"desc_en": "",
	"name_ru": "Россия",
	"desc_ru": ""
}
*/
```

Methods Reference
-----------------

[](#methods-reference)

### `PhoneHelper` class

[](#phonehelper-class)

- `clear(string $number): string` - Removes all non-digit characters from phone number
- `normalNumber(string $number): ?string` - Returns normalized number if valid, null otherwise
- `asString(string $number, ?string $mask = null): string` - Formats number according to mask
- `getCode(string $number): ?array` - Returns country code information for the number

### `PhoneFilter` class

[](#phonefilter-class)

A Yii2 validator filter that automatically normalizes phone numbers in model attributes.

License
-------

[](#license)

This extension is released under the MIT License. See the bundled [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

If you have any questions or issues, please create an issue on GitHub or contact the author at .

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance57

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

285d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6193985?v=4)[Александр Касьянов](/maintainers/carono)[@carono](https://github.com/carono)

---

Top Contributors

[![carono](https://avatars.githubusercontent.com/u/6193985?v=4)](https://github.com/carono "carono (2 commits)")

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/carono-yii2-phone-helper/health.svg)

```
[![Health](https://phpackages.com/badges/carono-yii2-phone-helper/health.svg)](https://phpackages.com/packages/carono-yii2-phone-helper)
```

###  Alternatives

[vyants/yii2-daemon

Extension provides functionality for simple daemons creation and control

7859.0k](/packages/vyants-yii2-daemon)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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