genderapi/phone-validator
最新稳定版本:v1.0.5
Composer 安装命令:
composer require genderapi/phone-validator
包简介
PHP SDK for validating and formatting phone numbers using the GenderAPI Phone Number Validation & Formatter API (https://genderapi.io)
README 文档
README
The phone-validator-php library uses the official GenderAPI Phone Number Validation & Formatter API to validate and format phone numbers from over 240 countries.
Whether your users enter phone numbers in various formats (e.g., 12128675309, +1 212 867 5309, 001-212-867-5309), this library will intelligently detect, validate, and convert the input into a standardized E.164 format (e.g., +12128675309).
✅ Features
- Converts phone numbers to E.164 format
- Validates if number is real and structurally possible
- Detects number type: mobile, landline, VoIP, etc.
- Identifies region/city based on area code
- Includes country-level metadata (e.g. ISO code)
- Built with PHP, works with Composer autoloading
📦 Installation
composer require genderapi/phone-validator
Or manually:
git clone https://github.com/GenderAPI/phone-validator-php.git
cd phone-validator-php
composer install
🚀 Usage
require_once __DIR__ . '/vendor/autoload.php'; use GenderApi\PhoneValidator; $validator = new PhoneValidator('YOUR_API_KEY'); $response = $validator->validate('+1 212 867 5309', 'US'); print_r($response);
📝 Input Parameters
validate(string $number, string|null $address = null): array
| Parameter | Type | Required | Description |
|---|---|---|---|
number |
string | ✅ Yes | Phone number in any format |
address |
string | Optional | ISO country code (US), full country name (Turkey), or city name (Berlin) – helps resolve local numbers |
Example:
$validator->validate('2128675309', 'US');
📤 API Response
{
"status": true,
"remaining_credits": 15709,
"expires": 0,
"duration": "18ms",
"regionCode": "US",
"countryCode": 1,
"country": "United States",
"national": "(212) 867-5309",
"international": "+1 212-867-5309",
"e164": "+12128675309",
"isValid": true,
"isPossible": true,
"numberType": "FIXED_LINE_OR_MOBILE",
"nationalSignificantNumber": "2128675309",
"rawInput": "+1 212 867 5309",
"isGeographical": true,
"areaCode": "212",
"location": "New York City (Manhattan)"
}
📘 Response Field Reference
| Field | Type | Description |
|---|---|---|
status |
Boolean | Was the request successful |
remaining_credits |
Integer | Remaining API credits |
regionCode |
String | ISO 3166-1 alpha-2 code (e.g. US) |
country |
String | Country name |
e164 |
String | Number formatted to E.164 |
isValid |
Boolean | Is number valid according to numbering rules |
isPossible |
Boolean | Is number structurally possible |
numberType |
String | Number type (MOBILE, FIXED_LINE, etc.) |
areaCode |
String | Area code from input |
location |
String | City/region matched from area code |
🔢 Number Type Values
| Value | Description |
|---|---|
FIXED_LINE |
Landline |
MOBILE |
Mobile phone |
FIXED_LINE_OR_MOBILE |
Ambiguous, could be both |
TOLL_FREE |
e.g. 800 numbers |
PREMIUM_RATE |
Expensive premium numbers |
SHARED_COST |
Cost shared between parties |
VOIP |
Internet-based phone |
PERSONAL_NUMBER |
Forwarding number |
PAGER |
Obsolete pager number |
VOICEMAIL |
Voicemail access |
UNKNOWN |
Cannot be determined |
ℹ️ More Information
- Supports 240+ countries and territories
- Detects mobile vs. landline automatically
- Great for sign-up forms, CRMs, messaging tools, and more
- More details: GenderAPI Docs
📄 License
MIT License © GenderAPI
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-03