Smart Phone Number 📱
A powerful Flutter package for detecting, validating, and verifying phone numbers with WhatsApp integration. It automatically detects the country code from the number prefix and validates if the number exists on WhatsApp.
Features
- 🎯 Automatic Country Detection: Detects the country from the number prefix
- 🌍 IP Geolocation: Uses IP to resolve conflicts between similar prefixes
- 💬 WhatsApp Validation: Checks if the phone number exists on WhatsApp
- 🔧 Flexible API: Multiple ways to validate numbers
- 🌐 Multi-language Support: Country names in both English and Arabic
- 📱 Cross-platform: Works on Android, iOS, and Web
Getting Started
Installation
Add this to your pubspec.yaml:
dependencies:
smart_phone_number: ^1.0.4
Then run:
flutter pub get
Usage
Basic Usage - Auto Detection
import 'package:smart_phone_number/smart_phone_number.dart';
// Automatically detect country and validate WhatsApp
PhoneResult result = await SmartPhoneNumber.detectAndValidate('712345678');
if (result.success) {
print('✅ WhatsApp account found!');
print('📱 Number: ${result.phoneNumber}');
print('🌍 Country Code: ${result.countryCode}');
print('📍 Region: ${result.regionCode}');
} else {
print('❌ ${result.message}');
}
Manual Country Code Selection
// Specify country code manually
PhoneResult result = await SmartPhoneNumber.validateWithCountryCode(
phoneNumber: '712345678',
countryCode: '967', // Yemen
);
// Force using specific country code even if number starts with another code
PhoneResult result = await SmartPhoneNumber.validateWithCountryCode(
phoneNumber: '966712345678', // Saudi number
countryCode: '967', // Treat as Yemen
forceCountryCode: true, // Force Yemen code
);
Detect Possible Countries
// Get all possible countries for a number
List<CountryData> countries = SmartPhoneNumber.detectPossibleCountries('712345678');
for (var country in countries) {
print('${country.nameAr} (${country.name}) - +${country.code}');
}
// Generate all possible number formats
List<String> possibilities = SmartPhoneNumber.generatePossibleNumbers('712345678');
for (var number in possibilities) {
print('Possible: $number');
}
Using Country Data
// Get country by code
CountryData? yemen = SmartPhoneNumber.getCountryByCode('967');
print(yemen?.nameAr); // اليمن
// Get country by region code
CountryData? saudi = SmartPhoneNumber.getCountryByRegion('SA');
print(saudi?.name); // Saudi Arabia
// Use CountryData directly
CountryData saudi = SmartPhoneNumber.getCountryByCode('966')!;
PhoneResult result = await SmartPhoneNumber.validateWithCountry(
'512345678',
saudi,
);
Supported Countries
Arab Countries
| Country | Code | Prefixes | Length |
|---|---|---|---|
| 🇾🇪 Yemen | 967 | 71, 73, 77, 70, 78 | 9 |
| 🇸🇦 Saudi Arabia | 966 | 5, 05 | 9 |
| 🇯🇴 Jordan | 962 | 77, 78, 79, 7 | 9 |
| 🇪🇬 Egypt | 20 | 10, 11, 12, 15, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109 | 10 |
| 🇮🇶 Iraq | 964 | 77, 78, 79, 75, 76, 71, 73 | 10 |
| 🇸🇩 Sudan | 249 | 91, 92, 93, 94, 95, 96, 99, 10, 11, 12 | 9 |
| 🇦🇪 UAE | 971 | 50, 52, 55, 56, 58 | 9 |
| 🇰🇼 Kuwait | 965 | 5, 6, 9, 4 | 8 |
| 🇶🇦 Qatar | 974 | 33, 55, 66, 77 | 8 |
| 🇧🇭 Bahrain | 973 | 36, 66, 77 | 8 |
| 🇴🇲 Oman | 968 | 71, 72, 73, 78, 79, 90, 91, 92 | 8 |
| 🇱🇧 Lebanon | 961 | 70, 71, 76, 78, 79, 81, 3 | 8 |
| 🇵🇸 Palestine | 970 | 56, 58, 59 | 9 |
| 🇱🇾 Libya | 218 | 91, 92, 94, 95 | 9 |
| 🇹🇳 Tunisia | 216 | 21, 22, 23, 51, 52, 53, 54, 55, 56, 91, 92, 93, 94, 95 | 8 |
| 🇩🇿 Algeria | 213 | 5, 6, 7 | 9 |
| 🇲🇦 Morocco | 212 | 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 | 9 |
| 🇲🇷 Mauritania | 222 | 2, 3, 4, 5 | 8 |
| 🇸🇴 Somalia | 252 | 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 90, 91 | 8 |
| 🇩🇯 Djibouti | 253 | 77 | 8 |
| 🇰🇲 Comoros | 269 | 32, 33, 34, 35, 36, 37, 38, 39, 76, 77 | 7 |
International Countries
| Country | Code | Prefixes | Length |
|---|---|---|---|
| 🇺🇸 United States | 1 | 2, 3, 4, 5, 6, 7, 8, 9 | 10 |
| 🇬🇧 United Kingdom | 44 | 7 | 10 |
| 🇩🇪 Germany | 49 | 15, 16, 17 | 10-11 |
| 🇫🇷 France | 33 | 6, 7 | 9 |
| 🇮🇹 Italy | 39 | 3 | 10 |
| 🇪🇸 Spain | 34 | 6, 7 | 9 |
| 🇹🇷 Turkey | 90 | 5, 53, 54, 55 | 10 |
| 🇷🇺 Russia | 7 | 9 | 10 |
| 🇨🇳 China | 86 | 1 | 11 |
| 🇮🇳 India | 91 | 6, 7, 8, 9 | 10 |
| 🇵🇰 Pakistan | 92 | 3 | 10 |
| 🇧🇩 Bangladesh | 880 | 1, 7, 8, 9 | 10 |
| 🇮🇩 Indonesia | 62 | 8 | 10-12 |
| 🇲🇾 Malaysia | 60 | 1 | 9-10 |
| 🇦🇺 Australia | 61 | 4 | 9 |
| 🇨🇦 Canada | 1 | 2, 3, 4, 5, 6, 7, 8, 9 | 10 |
| 🇧🇷 Brazil | 55 | 11, 12, 13, 14, 15, 16, 17, 18, 19 | 11 |
| 🇿🇦 South Africa | 27 | 6, 7, 8 | 9 |
| 🇳🇬 Nigeria | 234 | 70, 80, 81, 90, 91 | 10 |