Skip to content

DecksPlayer/phonevalidator

Repository files navigation

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.

Supported Countries

This package currently supports 245 countries/territories.

Source of truth: lib/src/assets/supported_countries.dart.

Full list (ISO, country, dial code)
ISO Country Dial Code
AC Isla de la Ascensión +247
AD Andorra +376
AE United Arab Emirates +971
AF Afghanistan +93
AG Antigua and Barbuda +1
AI Anguilla +1
AL Albania +355
AM Armenia +374
AO Angola +244
AR Argentina +54
AS Samoa Americana +1
AT Austria +43
AU Australia +61
AW Aruba +297
AX Islas Aland +358
AZ Azerbaijan +994
BA Bosnia and Herzegovina +387
BB Barbados +1
BD Bangladesh +880
BE Belgium +32
BF Burkina Faso +226
BG Bulgaria +359
BH Bahrain +973
BI Burundi +257
BJ Benin +229
BL San Bartolomé +590
BM Bermudas +1
BN Brunei +673
BO Bolivia +591
BQ Caribe neerlandés +599
BR Brazil +55
BS Bahamas +1
BT Bhutan +975
BW Botswana +267
BY Belarus +375
BZ Belize +501
CA Canada +1
CC Islas Cocos +61
CD Congo - Kinshasa +243
CF Central African Republic +236
CG Congo +242
CH Switzerland +41
CI Côte d’Ivoire +225
CK Islas Cook +682
CL Chile +56
CM Cameroon +237
CN China +86
CO Colombia +57
CR Costa Rica +506
CU Cuba +53
CV Cape Verde +238
CW Curazao +599
CX Isla de Navidad +61
CY Cyprus +357
CZ Czech Republic +420
DE Germany +49
DJ Djibouti +253
DK Denmark +45
DM Dominica +1
DO Dominican Republic +1
DZ Algeria +213
EC Ecuador +593
EE Estonia +372
EG Egypt +20
EH Sáhara Occidental +212
ER Eritrea +291
ES Spain +34
ET Ethiopia +251
FI Finland +358
FJ Fiji +679
FK Islas Malvinas +500
FM Micronesia +691
FO Islas Feroe +298
FR France +33
GA Gabon +241
GB United Kingdom +44
GD Grenada +1
GE Georgia +995
GF Guayana Francesa +594
GG Guernesey +44
GH Ghana +233
GI Gibraltar +350
GL Greenland +299
GM Gambia +220
GN Guinea +224
GP Guadalupe +590
GQ Equatorial Guinea +240
GR Greece +30
GT Guatemala +502
GU Guam +1
GW Guinea-Bissau +245
GY Guyana +592
HK Hong Kong +852
HN Honduras +504
HR Croatia +385
HT Haiti +509
HU Hungary +36
ID Indonesia +62
IE Ireland +353
IL Israel +972
IM Isla de Man +44
IN India +91
IO Territorio Británico del Océano Índico +246
IQ Iraq +964
IR Iran +98
IS Iceland +354
IT Italy +39
JE Jersey +44
JM Jamaica +1
JO Jordan +962
JP Japan +81
KE Kenya +254
KG Kyrgyzstan +996
KH Cambodia +855
KI Kiribati +686
KM Comoros +269
KN Saint Kitts and Nevis +1
KP North Korea +850
KR South Korea +82
KW Kuwait +965
KY Islas Caimán +1
KZ Kazakhstan +7
LA Laos +856
LB Lebanon +961
LC Saint Lucia +1
LI Liechtenstein +423
LK Sri Lanka +94
LR Liberia +231
LS Lesotho +266
LT Lithuania +370
LU Luxembourg +352
LV Latvia +371
LY Libya +218
MA Morocco +212
MC Monaco +377
MD Moldova +373
ME Montenegro +382
MF San Martín +590
MG Madagascar +261
MH Marshall Islands +692
MK North Macedonia +389
ML Mali +223
MM Myanmar +95
MN Mongolia +976
MO RAE de Macao (China) +853
MP Islas Marianas del Norte +1
MQ Martinica +596
MR Mauritania +222
MS Montserrat +1
MT Malta +356
MU Mauritius +230
MV Maldives +960
MW Malawi +265
MX Mexico +52
MY Malaysia +60
MZ Mozambique +258
NA Namibia +264
NC Nueva Caledonia +687
NE Niger +227
NF Isla Norfolk +672
NG Nigeria +234
NI Nicaragua +505
NL Netherlands +31
NO Norway +47
NP Nepal +977
NR Nauru +674
NU Niue +683
NZ New Zealand +64
OM Oman +968
PA Panama +507
PE Peru +51
PF Polinesia Francesa +689
PG Papua New Guinea +675
PH Philippines +63
PK Pakistan +92
PL Poland +48
PM San Pedro y Miquelón +508
PR Puerto Rico +1
PS Palestine +970
PT Portugal +351
PW Palau +680
PY Paraguay +595
QA Qatar +974
RE Reunión +262
RO Romania +40
RS Serbia +381
RU Russia +7
RW Rwanda +250
SA Saudi Arabia +966
SB Solomon Islands +677
SC Seychelles +248
SD Sudan +249
SE Sweden +46
SG Singapore +65
SH Santa Elena +290
SI Slovenia +386
SJ Svalbard y Jan Mayen +47
SK Slovakia +421
SL Sierra Leone +232
SM San Marino +378
SN Senegal +221
SO Somalia +252
SR Suriname +597
SS South Sudan +211
ST Sao Tome and Principe +239
SV El Salvador +503
SX Sint Maarten +1
SY Syria +963
SZ Eswatini +268
TA Tristán de Acuña +290
TC Islas Turcas y Caicos +1
TD Chad +235
TG Togo +228
TH Thailand +66
TJ Tajikistan +992
TK Tokelau +690
TL Timor-Leste +670
TM Turkmenistan +993
TN Tunisia +216
TO Tonga +676
TR Turkey +90
TT Trinidad and Tobago +1
TV Tuvalu +688
TW Taiwan +886
TZ Tanzania +255
UA Ukraine +380
UG Uganda +256
US United States +1
UY Uruguay +598
UZ Uzbekistan +998
VA Vatican City +379
VC Saint Vincent and the Grenadines +1
VE Venezuela +58
VG Islas Vírgenes Británicas +1
VI Islas Vírgenes de EE. UU. +1
VN Vietnam +84
VU Vanuatu +678
WF Wallis y Futuna +681
WS Samoa +685
XK Kosovo +383
YE Yemen +967
YT Mayotte +262
ZA South Africa +27
ZM Zambia +260
ZW Zimbabwe +263

🧩 Widgets

Widget Description
PhoneSummaryView A 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.
PhoneInputSelectorView An 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.
PhoneAutoDetectView An 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 Code Phone Number Expected Validation Country
+54 1123456789 Valid Argentina
+1 2025550191 Valid USA
+1 4165550123 Valid Canada
+44 2079460958 Valid UK
+49 30123456 Valid Germany
+33 612345678 Valid France
+34 612345678 Valid Spain
+55 11912345678 Valid Brasil
+52 5512345678 Valid Mexico
+91 9123456789 Valid India
+61 412345678 Valid Australia
+81 7012345678 Valid Japan
+82 1012345678 Valid South Korea
+7 9123456789 Valid Russia
+27 821234567 Valid South Africa
+39 3123456789 Valid Italy
+86 13812345678 Valid China
+92 3001234567 Valid Pakistan
+234 8031234567 Valid Nigeria
+880 1712345678 Valid Bangladesh
+20 1001234567 Valid Egypt
+62 81234567890 Valid Indonesia
+63 9171234567 Valid Philippines
+66 812345678 Valid Thailand
+966 501234567 Valid Saudi Arabia
+98 9123456789 Valid Iran
+60 123456789 Valid Malaysia
+31 612345678 Valid Netherlands
+48 500123456 Valid Poland
+40 712345678 Valid Romania
+380 501234567 Valid Ukraine
+56 912345678 Valid Chile
+57 3001234567 Valid Colombia
+51 912345678 Valid Peru
+58 4121234567 Valid Venezuela
+213 512345678 Valid Algeria
+244 912345678 Valid Angola
+229 61234567 Valid Benin
+267 71234567 Valid Botswana
+226 61234567 Valid Burkina Faso
+257 61234567 Valid Burundi
+237 61234567 Valid Cameroon
+238 61234567 Valid Cape Verde
+242 2221234567 Valid Congo
+243 81234567 Valid Congo - Kinshasa
+253 61234567 Valid Djibouti
+236 61234567 Valid Central African Republic
+240 91234567 Valid Equatorial Guinea
+291 61234567 Valid Eritrea
+251 91234567 Valid Ethiopia
+220 91234567 Valid Gambia
+233 201234567 Valid Ghana
+241 61234567 Valid Gabon
+224 61234567 Valid Guinea
+245 61234567 Valid Guinea-Bissau
+254 71234567 Valid Kenya
+269 61234567 Valid Comoros
+225 61234567 Valid Chad
+266 61234567 Valid Lesotho
+231 61234567 Valid Liberia
+218 61234567 Valid Libya
+232 61234567 Valid Malawi
+261 61234567 Valid Madagascar
+265 61234567 Valid Maldives
+223 61234567 Valid Mali

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors