GetCountryCode

Content Type: Widget
Categories: Utility,User Interface,Visualization

Overview

 

The Phone Country Code Finder widget is a convenient tool designed for easily extracting country-specific information from a phone number. It leverages phone number parsing libraries to identify the country, country codes (both alpha-2 and alpha-3), and full country names based on a given phone number.

This widget is ideal for use cases such as:

  • Identifying the country of a user based on their phone number input.
  • Displaying country information for international form inputs.
  • Automating country code validation or country selection in global applications.

Key Features:

  • Country Name: Retrieves the full country name from the phone number.
  • Alpha-2 Country Code: Returns the ISO 3166-1 alpha-2 code (2-letter country code).
  • Alpha-3 Country Code: Returns the ISO 3166-1 alpha-3 code (3-letter country code).
  • Robust Parsing: Utilizes the libphonenumber-js library to handle phone number parsing and validation.
  • Customizable Output: Tailor the output to show the country name, alpha-2 or alpha-3 country code based on your requirements.

Documentation

Typical Usage Scenario

The GetCountryCode widget is designed to extract country information from a given phone number. It helps developers and businesses automatically determine country names and codes based on international dialing codes. This can be useful in applications that require country-based validation, user profiling, or localization.

Use cases include:

  • Validating phone numbers during user registration.
  • Auto-filling country fields in forms.
  • Providing country-based customizations in applications.

Features and Limitations

Features:

  • Extracts country name, Alpha-2 code, and Alpha-3 code from a phone number.
  • Supports international phone number formats.
  • Provides a clean UI output based on the selected country format.
  • Logs informative messages to help debug issues.

Limitations:

  • Requires phone numbers to be in a valid international format.
  • Relies on external dependencies for phone number parsing.
  • Does not handle invalid or incomplete phone numbers gracefully.

Configuration 

  1. Phone Number Input: Pass the phone number as a string prop to the widget.
  2. CSS Class: Provide a class name for custom styling.
  3. Country Selection Mode: Choose one of the following options:
    • countryName - Displays the full country name.
    • alphaCode2 - Returns the 2-letter country code.
    • alphaCode3 - Returns the 3-letter country code.

Frequently Asked Questions 

  1. What happens if an invalid phone number is provided?

    • The widget logs an error message and returns an empty string.
  2. Can this widget be used in a native mobile application?

    • Yes, but it requires proper handling of dependencies.
  3. Does this support all international phone numbers?

    • Yes, as long as they are formatted correctly and libphonenumber-js supports them.

Releases

Version: 1.0.0
Framework Version: 10.13.0
Release Notes: Introduced the GetCountryDetails widget for extracting country details from a phone number. Supports the following country data retrieval: Country Name Alpha-2 Country Code Alpha-3 Country Code Uses the libphonenumber-js package to parse phone numbers and extract country codes. Integrated country-kit to fetch country details based on Alpha-2 codes. Includes a country selection feature allowing users to specify whether they want the country name, Alpha-2, or Alpha-3 code. Added basic error handling for invalid or missing phone numbers. Console logs provide additional debugging information.