smart_phone_number 1.0.6 copy "smart_phone_number: ^1.0.6" to clipboard
smart_phone_number: ^1.0.6 copied to clipboard

A smart phone number parser that automatically detects country codes from number prefixes and validates WhatsApp accounts

Smart Phone Number 📱 #

pub package package popularity package points

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.6

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

🆕 Newly Added Countries (10 Countries) #

Country Code Prefixes Length
🇦🇫 Afghanistan 93 70-79 9
🇮🇷 Iran 98 90-99 10
🇳🇵 Nepal 977 93-98 10
🇱🇰 Sri Lanka 94 71-78 9
🇲🇲 Myanmar 95 93-99 9-10
🇪🇹 Ethiopia 251 90-99 9
🇰🇪 Kenya 254 70-79 9
🇹🇿 Tanzania 255 61-69, 71-79 9
🇺🇬 Uganda 256 31-32, 70-79 9
🇬🇭 Ghana 233 20, 24, 27, 50, 54-55, 57, 59 9
1
likes
160
points
546
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A smart phone number parser that automatically detects country codes from number prefixes and validates WhatsApp accounts

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, get_country_ip, url_launcher

More

Packages that depend on smart_phone_number