PHPackages                             floor12/yii2-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. floor12/yii2-phone

ActiveYii2-component[Validation &amp; Sanitization](/categories/validation)

floor12/yii2-phone
==================

Yii2 phone formatter and validator.

2.2.3(2y ago)315.5k↓17.3%23MITPHPPHP &gt;=7.1.0

Since Jul 27Pushed 2y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (18)Used By (3)

yii2-phone
==========

[](#yii2-phone)

Formatter and validator form phone numbers

*Этот файл доступен на [русском языке](README_RU.md).*

[![Build Status](https://camo.githubusercontent.com/423fb405187473ec311b16940b33a8705b828eeaf5dc288485adc1bbe3584095/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666c6f6f7231322f796969322d70686f6e652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/floor12/yii2-phone/build-status/master)[![Code quality score](https://camo.githubusercontent.com/60e59d7f43f6105d32c65a772ee5435c569ce9f108615ba58fc067ab63a6a706/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666c6f6f7231322f796969322d70686f6e652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/floor12/yii2-phone/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/f45769188529ad6aadd6e2dc771c9de5ad23b51597f194eaf85d21085350cbc0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f666c6f6f7231322f796969322d70686f6e652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/floor12/yii2-phone/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/4057db7cc8fe41ed20207bf7f175fba9d69131b01ddf9503bd6c5c9cf51c7980/68747470733a2f2f706f7365722e707567782e6f72672f666c6f6f7231322f796969322d70686f6e652f762f737461626c65)](https://packagist.org/packages/floor12/yii2-phone)[![Total Downloads](https://camo.githubusercontent.com/aeaff28af53279b941d41bd7725b522b265c3b668a67158c952064fcec97f58f/68747470733a2f2f706f7365722e707567782e6f72672f666c6f6f7231322f796969322d70686f6e652f646f776e6c6f616473)](https://packagist.org/packages/floor12/yii2-phone)[![License](https://camo.githubusercontent.com/c5acc881da2fb6af583f3f6fcebdc28d5b2cb678d8a54bf5e4f9498d85ce97a1/68747470733a2f2f706f7365722e707567782e6f72672f666c6f6f7231322f796969322d70686f6e652f6c6963656e7365)](https://packagist.org/packages/floor12/yii2-phone)

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

[](#installation)

To use this extension run this command:

```
$ composer require floor12/yii2-phone
```

or add this to the `require` section of your composer.json.

```
"floor12/yii2-phone": "dev-master"
```

Usage
-----

[](#usage)

This extension allows to validate phone numbers and save only numbers in db without any formatting. It also include simple formatter to render formatted phone numbers as string or html `` tag.

### Phone validation

[](#phone-validation)

To store phone number in database, ActiveRecord model database field should be VARCHAR(15).

The validator has backend and frontend (js) validation. To validate your field, add `floor12\phone\PhoneValidator` to `ActiveRecord::rules()` action like this:

```
use floor12\phone\PhoneValidator;
use yii\base\Model;

class User extends Model
{

    public $phone;

    public function rules()
    {
        return [
            ['phone', PhoneValidator::class]
        ];
    }
}
```

### Phone formatting

[](#phone-formatting)

Class `floor12\phone\PhoneFormatter` allows to render phone number as formatted string or as html ``, and has two static methods:

- `PhoneFormatter::format($phone)`
- `PhoneFormatter::a($phone,array $options= [])`

*Formatting examples*

```
echo PhoneFormatter::format(79461234565);                       # +7 (946) 123-45-65
echo PhoneFormatter::a(79461234565);                            # +7 (946) 123-45-65
echo PhoneFormatter::a(79461234565,['class'=>'phone-link']);    # +7 (946) 123-45-65
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 97.7% 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 ~130 days

Recently: every ~93 days

Total

15

Last Release

1028d ago

Major Versions

1.0.4 → 2.0.02019-11-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/8dc98d778cb18db41a1e5b9df722c56f65f655de44fe0d581484cd8dea31b928?d=identicon)[floor12](/maintainers/floor12)

---

Top Contributors

[![floor12](https://avatars.githubusercontent.com/u/8406969?v=4)](https://github.com/floor12 "floor12 (42 commits)")[![ArtMin96](https://avatars.githubusercontent.com/u/29732308?v=4)](https://github.com/ArtMin96 "ArtMin96 (1 commits)")

---

Tags

formattervalidatorphonefloor12

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[laravel-validation-rules/phone

Validate that a phone number is in the correct format

69355.5k](/packages/laravel-validation-rules-phone)[paulzi/yii2-json-behavior

Yii2 json attribute behavior

76528.6k3](/packages/paulzi-yii2-json-behavior)[ellisio/laravel-phone

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

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

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

2861.3k](/packages/stuyam-laravel-phone-validator)[laravel-validation-rules/us-state

Validate US States and Canada Provinces

16172.7k](/packages/laravel-validation-rules-us-state)[codeonyii/yii2-at-least-validator

Validates at least one (or more) attributes.

28253.5k1](/packages/codeonyii-yii2-at-least-validator)

PHPackages © 2026

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