shankar/country-phone-validator
最新稳定版本:v1.0.1
Composer 安装命令:
composer require shankar/country-phone-validator
包简介
Laravel package to validate phone numbers using country name or dial code
README 文档
README
A Laravel package for validating mobile phone numbers across different countries with additional features.
Features
- Validate phone numbers for 200+ countries
- Check if a number belongs to a specific country
- Get country code from phone number
- Format phone numbers according to international standards
- Support for custom validation rules
- Easy integration with Laravel validation system
Installation
You can install this package via Composer:
composer require shankar/country-phone-validator
The package will be auto-discovered by Laravel. If you are not using package auto-discovery, add the service provider to your config/app.php:
'providers' => [ // ... Shankar\CountryPhoneValidator\CountryPhoneValidatorServiceProvider::class, ],
Usage
Basic Phone Number Validation
use Shankar\CountryPhoneValidator\Rules\PhoneNumber; $request->validate([ 'phone' => ['required', new PhoneNumber], ]);
Validate by Country Name
use Shankar\CountryPhoneValidator\Rules\ValidPhoneByCountryName; $request->validate([ 'phone' => ['required', new ValidPhoneByCountryName('India')], ]);
Validate by Dial Code
use Shankar\CountryPhoneValidator\Rules\ValidPhoneByDialCode; $request->validate([ 'phone' => ['required', new ValidPhoneByDialCode('+91')], ]);
Country Names and Dial Codes
You can retrieve the list of supported countries with their dial codes and validation regex using the Countries class:
use Shankar\CountryPhoneValidator\Countries; $countries = Countries::all(); // Example output: // [ // [ // 'name' => 'India', // 'dial_code' => '+91', // 'regex' => '/^...$/' // ], // ... // ]
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-28