juanparati/mobile-numbers
Composer 安装命令:
composer require juanparati/mobile-numbers
包简介
An international mobile number validator
README 文档
README
MobileNumbers
What is it?
A library that validate and parse mobile phone numbers.
Right now only phone numbers from the following countries are validated:
| Country | Code |
|---|---|
| Germany | DE |
| Denmark | DK |
| Spain | ES |
| Finland | FI |
| France | FR |
| Italy | IT |
| Norway | NO |
| Poland | PL |
| Sweden | SE |
| South Africa | ZA |
Feel free to fork this project and add new countries.
Installation
composer require juanparati/mobile-numbers
How it works
Validate a phone number:
Validator::country('ES')->isValid('651365485');
It is possible to validate phone numbers that contains the international country code:
Validator::country('DK')->isValid('+4560514180'); Validator::country('SE')->isValid('0046767164315');
The library provides helper that convert different phone number formats to E.164:
$validator = Validator::country('PL'); $raw_number = '(669) 823-955'; $e164_number = $validator->helper->convertToE164($raw_number); // Convert number to "669823955" echo ($validator->isValid($e164_number) ? 'Valid!' : 'Not Valid!'); $validator = Validator::country('SE'); $raw_number = '(+46) 7 37322 0-66'; $e164_number = $validator->helper->convertToE164($raw_number); // Convert number to "+46737322066" echo ($validator->isValid($e164_number) ? 'Valid!' : 'Not Valid!');
It is also possible to add a valid country code to number without country code:
Validator::country('SE')->addCountryCode('0737321066'); // +46737321066 Validator::country('DK')->addCountryCode('60515290'); // +4560515290 Validator::country('DK')->addCountryCode('+4560515290'); // +4560515290 (Country code is not added again) Validator::country('DK')->addCountryCode('004560515290'); // 004560515290 (Country code is not added again)
or stripe the country code
Validator::country('SE')->stripCountryCode('0046737321066'); // 0737321066 Validator::country('FI')->stripCountryCode('00358411234567'); // 0411234567 Validator::country('ES')->stripCountryCode('+34670862595'); // 670862595
Other methods:
Validator::country('ES')->helper->hasCountryCode('0030670862595'); // True Validator::country('ES')->hasValidCountryCode('0030670862595'); // False
Definitions list
Using the helper method "getAllDefinitions" it will obtain the information about the all the codes used in all the definitions:
$definitions = Helper::getAllDefinitions();
The definitions include country prefix code, country code and country flag information.
Identify phone numbers
Using the helper method "identifyNumber" is possible the identify the country which belongs the phone number. The phone number should contains the international prefix.
Example:
Helper::identifyNumber('+4560514180'); // Returns DK
Add your country definition
- Fork this project
- Add a new definition into ./src/Definitions
- Add a new unit test into ./tests/Definitions
Backers and contributors
- Matchbanker.fi (Backer)
juanparati/mobile-numbers 适用场景与选型建议
juanparati/mobile-numbers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.5k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 11 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 juanparati/mobile-numbers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 juanparati/mobile-numbers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2017-11-09