country_mobile_validator

Pub Version Pub Points Pub Likes CI License


country_mobile_validator showcase


A high-performance, pure Dart phone number validation library with telecom operator detection (Jio, Airtel, Vi, BSNL), 249-country mobile-only validation, SMS OTP deliverability checks, and WhatsApp click-to-chat URL generators.

Works seamlessly in Flutter, Dart Frog / Shelf backends, and command-line tools with zero native platform dependencies.


โšก Key Features

Feature Description Real-World Benefit
Telecom Carrier Detection Identifies cellular carrier (Jio, Airtel, Vi, BSNL) and state circle Network-aware auth & billing
Strict Mobile-Only Validation Rejects landlines, toll-free, and premium numbers Saves costly failed SMS OTP sends
Zero-Boilerplate Extensions Direct helpers on String (isValidMobile(), detectCarrier()) 1-line validation
WhatsApp Chat Links Auto-generates toWhatsAppUrl(message: '...') Instant support & verification
Range-Aware Accuracy True national ranges (e.g. AR 10โ€“11, NZ 8โ€“10, IN 10) Prevents blocking valid users
Sub-Microsecond Speed Pure Dart with zero regex during basic checks (~8 ยตs/op) High-throughput backend validation

๐Ÿš€ Quick Usage

1. Zero-Boilerplate String Extensions

import 'package:country_mobile_validator/country_mobile_validator.dart';

// 1. Instant Mobile & OTP Deliverability Check
'+91 98765 43210'.isValidMobile();      // true
'+91 1800 111 222'.isOtpDeliverable();  // false (Toll-Free, cannot receive SMS)

// 2. Telecom Carrier & State Circle Detection
final carrier = '+91 70001 23456'.detectCarrier();
print(carrier?.displayName); // 'Jio True 5G'
print(carrier?.circle);      // 'National'

final bsnl = '+91 94220 12345'.detectCarrier();
print(bsnl?.displayName);    // 'BSNL Mobile'
print(bsnl?.circle);         // 'Maharashtra & Goa'

// 3. One-Click WhatsApp Click-to-Chat Link
final url = '+91 98765 43210'.toWhatsAppUrl(message: 'Hello Support');
// -> "https://wa.me/919876543210?text=Hello%20Support"

// 4. Clean National Formatting
'+919876543210'.formatNational(); // '98765 43210'

2. Global Auto-Detecting Validator

final result = validateMobile('+91 98765 43210');

if (result.isValid && result.isMobile) {
  print('Country: ${result.regionCode}'); // 'IN'
  print('E.164: +${result.countryCode}${result.nationalNumber}'); // '+919876543210'
} else {
  print('Invalid number: ${result.issue}');
}

3. Country-Pinned Validation (e.g. from country_code_picker)

final inValidator = mobileValidator.forRegion('IN');

print(inValidator.lengthHint);              // '10 digits'
print(inValidator.isMobileLength(10));      // true
print(inValidator.validate('9876543210').isValid); // true

๐Ÿ’– Support the Project

If you find this project useful, consider supporting its active maintenance and future development:

Buy Me A Coffee GitHub Sponsors Patreon


๐Ÿ“„ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Maintained with โค๏ธ by Govind Tank.

Libraries

country_mobile_validator
country_mobile_validator โ€” validate mobile numbers per country with real length ranges (8-10, 10-11 digits...), mobile-only type detection, telecom carrier identification, WhatsApp URLs, and a country_code_picker-friendly API.