djunehor / validate_nigerian_phone
这是一个PHP模块,用于验证和格式化尼日利亚电话号码,同时可以推断网络提供商或区号。
dev-master / 1.0.x-dev
2019-10-14 10:50 UTC
Requires
- php: ~5.6|~7.0
Requires (Dev)
- phpunit/phpunit: ^7.5
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-09-14 22:00:34 UTC
README
欢迎提交问题和pull请求。
这是一个PHP模块,用于验证和格式化尼日利亚电话号码,同时可以推断网络提供商或区号。
注意:由于尼日利亚于2013年实施了手机号码携带,网络解析功能可能不够准确,因此无法再通过号码前缀可靠地确定运营商。
目录
安装
使用composer安装:composer require djunehor/validate_nigerian_phone
在Laravel项目中
- 如果您使用的是Laravel 5.5及以上版本,则无需进一步操作
- 如果您使用的是Laravel < 5.5,则需要注册服务提供程序。打开config/app.php文件,并在提供者数组中添加以下内容:
Djunehor\Validator\PhoneValidatorServiceProvider::class
用法
在Laravel中
... /*This checks if the number supplied *is a valid nigerian number * either land line or mobile number */ public function controllerName(Request $request) { $request->validate( [ 'phone' => 'required|ngphone' ]); } //to validate if it's a mobile number $request->validate( [ 'phone' => 'required|ngphone:mobile' ]); //to validate if it's a landline $request->validate( [ 'phone' => 'required|ngphone:land' ]);
在PHP项目中
如果未启用自动加载,请在文件顶部添加require vendor/autoload.php
,然后
use \Djunehor\Validator\NigerianPhone; $phone = new NigerianPhone('+2348135087966'); // Check if is valid $phone->isValid(); // true // Get formatted $phone->formatted(); // 08135087966 // Get Network $phone->getNetwork(); // mtn // Check if is mtn $phone->isMtn(); // True // Get network from phone number prefix e.g $phone->getNetworkByPrefix('0703'); // mtn
特性
当前已实现
- isValid
- formatted
- getNetwork
- getAreaCode
- isMtn
- isGlo
- isAirtel
- is9mobile
- isSmile
- isMultilinks
- isVisafone
- isNtel
- isStarcomms
- isZoom
- getPrefixesByNetwork
- getNetworkByPrefix
- getAreaCodeByName
测试
- 运行
phpunit tests/NigerianPhoneTest.php
贡献
查看GitHub上的问题,并/或提交pull请求以贡献!