cellphone_validator 2.0.4

SDKflutter
Platformandroidioswindowslinuxmacosweb

A widget and helper for validation internation phone numbers

Cellphone Validator

A powerful and easy-to-use Flutter package for validating and formatting international phone numbers. Includes a customizable country code picker and provides detailed information for hundreds of countries. Screenshot 1 Screenshot 2 Screenshot 3

Features

  • Real-time Validation: Instantly check if a phone number is valid as the user types.
  • Automatic Formatting: Applies the correct formatting mask to the phone number automatically.
  • Integrated Country Picker: A clean UI widget that combines a country code dropdown with the phone number input field.
  • Reactive Controller: Built with a ValueNotifier-based controller to easily listen for changes to the phone number's validity and value.
  • Rich Country Data: Includes country names (with translations), ISO codes, dial codes, and flag emojis.

Getting Started

To start using the package, add the cellphone_validator dependency to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  cellphone_validator: ^<latest-version> # Replace with the latest version

Then, run flutter pub get in your terminal to install the package.

Features

🌐 Supported Languages

ar, de, en, es, fr, hi, id, it, ja, ko, pt, ru, ur — and more coming soon.

🧩 Widgets

WidgetDescription
PhoneSummaryViewA read-only widget that displays a fully formatted phone number, including the country code. Useful for showing validated numbers in a summary or review screen.
PhoneInputSelectorViewAn interactive widget that allows users to select a country from a dropdown and enter a phone number. Includes input formatting and real-time validation based on the selected country's phone rules.
PhoneAutoDetectViewAn intelligent phone input widget that automatically detects the country based on the dial code entered. It formats the number accordingly and provides real-time validation feedback.

Export List

cellphone_validator
  • path :package:cellphone_validator/cellphone_validator.dart
  • Description: Main package entry point. Re-exports all core classes, models, and widgets for easy access.
country_manager
  • path :package:cellphone_validator/src/controllers/country_manager.dart
  • Description: Provides logic for managing and retrieving supported countries.
country
  • path :package:cellphone_validator/src/controllers/country_manager.dart
  • Description: Defines the Country model, which includes dial codes, masks, and display data.
phone_validator
  • path :package:cellphone_validator/src/controllers/phone_validator.dart
  • Description: Core validator logic that checks if phone numbers are valid according to country-specific rules.
phone_auto_detect_view
  • path :package:cellphone_validator/src/view/phone_auto_detect_view/phone_auto_detect_view.dart
  • Description: Widget that auto-detects the country from the phone number and validates it.
phone_input_selector_view
  • path :package:cellphone_validator/src/view/phone_input_selector_view/phone_input_selector_view.dart
  • Description: Widget that allows manual country selection and phone input with validation.
phone_summary_view
  • path :package:cellphone_validator/src/view/phone_text_view/phone_summary_view.dart
  • Description: Widget that displays a phone number with formatting.

How to Use

1. Initialize

  • import the main package:
    • import 'package:cellphone_validator/cellphone_validator.dart';
      

2. Set Up Your App Widget

Create your main app widget as usual:

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

3. Create a PhoneValidator Controller in Your Stateful Widget

Create a PhoneValidator to manage phone validation and state.

 PhoneValidator phoneValidator = PhoneValidator(lang: 'en');

4. Build the UI Using Provided Widgets

Use the package’s widgets like PhoneInputSelectorView, PhoneSummaryView, and PhoneAutoDetectView to build your UI. For example:

/**
 *  How to use PhoneInputSelectorView
 * **/
PhoneInputSelectorView(phoneValidator: phoneValidator),
/**
 *  How to use PhoneSummaryView
 * **/
PhoneSummaryView(phoneValidator: phoneValidator, fullPhoneNumber: phoneValidator.phone.replaceAll('+', ''),)
/**
 *  How to use PhoneAutoDetectView
 * **/
 
PhoneAutoDetectView(phoneValidator: phoneValidator.value, fullPhoneNumber: ''),
  • How to check if some value is true or false

    ListenableBuilder(
      listenable: phoneValidator.isValidPhoneNotifier,
      builder: (context, _) {
      return phoneValidator.isValidPhoneNotifier.value
        ? 'trueAction'
          :'false action' 
      },
    ),

You can listen to the isValidPhoneNotifier within the controller to react to changes in the phone number's validity in real-time.

Summary

  • No need to load countries manually: The package handles it internally as a singleton.
  • Just initialize once with CellPhoneValidator.init().
  • Use the widgets with your PhoneValidator controller.
  • Switch languages on the fly using your language dropdown.
Testing Numbers
Country CodePhone NumberExpected ValidationCountry
+541123456789ValidArgentina
+12025550191ValidUSA
+14165550123ValidCanada
+442079460958ValidUK
+4930123456ValidGermany
+33612345678ValidFrance
+34612345678ValidSpain
+5511912345678ValidBrasil
+525512345678ValidMexico
+919123456789ValidIndia
+61412345678ValidAustralia
+817012345678ValidJapan
+821012345678ValidSouth Korea
+79123456789ValidRussia
+27821234567ValidSouth Africa
+393123456789ValidItaly
+8613812345678ValidChina
+923001234567ValidPakistan
+2348031234567ValidNigeria
+8801712345678ValidBangladesh
+201001234567ValidEgypt
+6281234567890ValidIndonesia
+639171234567ValidPhilippines
+66812345678ValidThailand
+966501234567ValidSaudi Arabia
+989123456789ValidIran
+60123456789ValidMalaysia
+31612345678ValidNetherlands
+48500123456ValidPoland
+40712345678ValidRomania
+380501234567ValidUkraine
+56912345678ValidChile
+573001234567ValidColombia
+51912345678ValidPeru
+584121234567ValidVenezuela
+213512345678ValidAlgeria
+244912345678ValidAngola
+22961234567ValidBenin
+26771234567ValidBotswana
+22661234567ValidBurkina Faso
+25761234567ValidBurundi
+23761234567ValidCameroon
+23861234567ValidCape Verde
+2422221234567ValidCongo
+24381234567ValidCongo - Kinshasa
+25361234567ValidDjibouti
+23661234567ValidCentral African Republic
+24091234567ValidEquatorial Guinea
+29161234567ValidEritrea
+25191234567ValidEthiopia
+22091234567ValidGambia
+233201234567ValidGhana
+24161234567ValidGabon
+22461234567ValidGuinea
+24561234567ValidGuinea-Bissau
+25471234567ValidKenya
+26961234567ValidComoros
+22561234567ValidChad
+26661234567ValidLesotho
+23161234567ValidLiberia
+21861234567ValidLibya
+23261234567ValidMalawi
+26161234567ValidMadagascar
+26561234567ValidMaldives
+22361234567ValidMali

Additional Information

  • Found a Bug or Have a Feature Request? Please file an issue on our GitHub repository.
  • Want to Contribute? We welcome pull requests! Feel free to fork the repository and submit your changes.
  • License: This package is licensed under the Apache 2.0 License. See the LICENSE file for more details.

Help this project

If you find this package helpful and want to support its development, consider making a donation. Thank you for your support!

Support via PayPal

Badges

Ask DeepWiki