udokmeci/yii2-phone-validator
Composer 安装命令:
composer require udokmeci/yii2-phone-validator
包简介
Modern Yii2 Phone validator wrapper on top of PhoneNumberUtil library also used by Android devices
README 文档
README
Yii2 phone number validator extension using Google's libphonenumber library.
Installation
composer require udokmeci/yii2-phone-validator
Usage
Basic Validation
use udokmeci\yii2PhoneValidator\PhoneValidator; class Contact extends ActiveRecord { public function rules() { return [ [['phone'], PhoneValidator::class, 'country' => 'NL'], ]; } }
Using Format Enum
use udokmeci\yii2PhoneValidator\PhoneValidator; use udokmeci\yii2PhoneValidator\PhoneNumberFormat; // Modern PHP 8.1+ enum usage public function rules() { return [ [['phone'], PhoneValidator::class, 'country' => 'NL', 'format' => PhoneNumberFormat::E164 // Enum case ], [['mobile'], PhoneValidator::class, 'country' => 'NL', 'format' => PhoneNumberFormat::INTERNATIONAL // Enum case ], ]; }
Dynamic Country Detection
public function rules() { return [ [['phone'], PhoneValidator::class, 'countryAttribute' => 'country_code'], ]; }
Custom Formatting
use udokmeci\yii2PhoneValidator\PhoneNumberFormat; public function rules() { return [ [['phone'], PhoneValidator::class, 'country' => 'NL', 'format' => PhoneNumberFormat::E164 // Using enum ], ]; }
Configuration
| Property | Description | Default |
|---|---|---|
country |
Fixed country code (ISO 3166-1 alpha-2) | null |
countryAttribute |
Model attribute containing country code | null |
strict |
Require country for validation | true |
format |
Output format | INTERNATIONAL |
Format Options
| Format | Example Output |
|---|---|
PhoneNumberFormat::E164 |
+31612345678 |
PhoneNumberFormat::INTERNATIONAL |
+31 6 12345678 |
PhoneNumberFormat::NATIONAL |
06 12345678 |
PhoneNumberFormat::RFC3966 |
tel:+31-6-12345678 |
false |
No formatting |
Note: PhoneNumberFormat is a modern PHP 8.1+ enum. Import: use udokmeci\yii2PhoneValidator\PhoneNumberFormat;
Examples
Netherlands Phone
// Input: '0612345678' // Output: '+31 6 12345678'
US Phone
[['phone'], PhoneValidator::class, 'country' => 'US'] // Input: '2125551234' // Output: '+1 212 555 1234'
Non-Strict Mode
[['phone'], PhoneValidator::class, 'strict' => false] // Validates only if country is available
Requirements
- PHP 8.1+
- Yii2 2.0.40+
- giggsey/libphonenumber-for-php ^8.13
Testing
Follow Yii2 Extension Testing Guidelines:
vendor/bin/phpunit vendor/bin/phpstan analyse vendor/bin/phpcs --standard=PSR12 src/
License
MIT License. See LICENSE file.
udokmeci/yii2-phone-validator 适用场景与选型建议
udokmeci/yii2-phone-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 225.64k 次下载、GitHub Stars 达 36, 最近一次更新时间为 2015 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2」 「phone number」 「phone number validator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 udokmeci/yii2-phone-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 udokmeci/yii2-phone-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 udokmeci/yii2-phone-validator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Phone helper & validator for Nette Framework
A custom URL rule class for Yii 2 which allows to create translated URL rules
Yii2 phone formatter and validator.
A package for working with arbitrary precision numbers in Laravel.
Gambling Algorithms for Certification.
Validates Turkish National Identification Number
统计信息
- 总下载量: 225.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 36
- 点击次数: 16
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-10