npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

p-intl-input-tel-gg

v18.0.6

Published

[![npm version](https://badge.fury.io/js/p-intl-input-tel-ggg.svg)](https://badge.fury.io/js/p-intl-input-tel-ggg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Downloads

156

Readme

📞 International Telephone Input for Angular

npm version License: MIT

🔄 Fork Information

This is a fork of p-intl-input-tel that fixes several critical issues:

Key Improvements Over Original

  • ✅ Fixed validation errors not being propagated to parent form controls
  • ✅ Encapsulate styles to prevent affecting other components
  • 🔄 Added proper paste handling with automatic formatting
  • ⚡ Implemented real-time validation
  • 🌍 Improved country code detection when pasting international numbers
  • 🚫 Fixed maxLength issues with international number formats
  • 🔍 Enhanced error messages and validation feedback

An Angular component for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods.

✨ Features

alt text

  • 🌍 International phone number formatting
  • 🚩 Country selection with flags
  • ✅ Real-time validation using google-libphonenumber
  • 📋 Smart paste handling with format detection
  • 🔍 Country search functionality
  • 💪 Fully typed with TypeScript
  • 🎨 Customizable styling
  • 🔄 Reactive Forms support
  • 🚫 Proper form validation integration

🔧 Version Compatibility

| Library Version | Angular | PrimeNG | | --------------- | ------- | ---------- | | 16.x.x | 16.x.x | >= 16.8.0 | | 17.x.x | 17.x.x | >= 17.2.0 | | 18.x.x | 18.x.x | >= 17.18.0 |

📦 Installation

1. Install Package and Dependencies

# Install the main package
npm install p-intl-input-tel-gg --save

# Install required dependencies
npm install google-libphonenumber primeng --save

2. Add Styles

Add the following to your angular.json styles array:

{
    "styles": ["./node_modules/p-intl-input-tel-gg/src/assets/style.scss"]
}

🚀 Usage

Basic Setup

// app.component.ts
import { IntlInputTelComponent } from 'p-intl-input-tel-gg';
import { CountryISO, PhoneNumberFormat, SearchCountryField } from 'p-intl-input-tel-gg';

@Component({
  // ...
  imports: [IntlInputTelComponent]
})

Template Integration

<form [formGroup]="phoneForm">
    <p-intl-tel-input-gg [favoriteCountries]="['US', 'GB', 'FR']" [enableAutoCountrySelect]="true" [displayPlaceholder]="true" [selectedCountryISO]="CountryISO.UnitedStates" [phoneValidation]="true" [separateDialCode]="true" [numberFormat]="PhoneNumberFormat.INTERNATIONAL" [searchCountryField]="[SearchCountryField.NAME, SearchCountryField.DIALCODE]" cssClass="custom-input" formControlName="phone"> </p-intl-tel-input-gg>
</form>

Form Validation Example

import { FormBuilder, FormGroup, Validators } from "@angular/forms";

export class AppComponent {
    phoneForm: FormGroup;

    constructor(private fb: FormBuilder) {
        this.phoneForm = this.fb.group({
            phone: ["", Validators.required],
        });
    }

    onSubmit() {
        if (this.phoneForm.valid) {
            console.log("Valid phone number:", this.phoneForm.get("phone").value);
        } else {
            // Form validation errors are now properly propagated
            const phoneControl = this.phoneForm.get("phone");
            if (phoneControl.errors?.["invalidNumber"]) {
                console.log("Invalid phone number");
            }
            if (phoneControl.errors?.["parseError"]) {
                console.log("Could not parse phone number");
            }
        }
    }
}

🚨 Validation Errors

The component now properly propagates these validation errors to the parent form:

| Error | Description | | ----------------- | ----------------------------------------------- | | invalidNumber | Phone number is invalid for the selected region | | parseError | Could not parse the input as a phone number | | invalidCountry | Selected country is invalid | | formatError | Error occurred while formatting the number | | unexpectedError | An unexpected error occurred during validation |

⚙️ Configuration Options

Input Properties

| Property | Type | Default | Description | | ----------------------- | ---------------------- | --------------------------------- | ----------------------------------- | | cssClass | string | 'control-form' | Custom CSS class for styling | | favoriteCountries | CountryISO[] | [] | Priority countries shown at the top | | onlyCountries | CountryISO[] | [] | Restrict to specific countries | | enableAutoCountrySelect | boolean | true | Auto-select country based on input | | displayPlaceholder | boolean | true | Show example number placeholder | | customPlaceholder | string | - | Override default placeholder | | numberFormat | PhoneNumberFormat | PhoneNumberFormat.INTERNATIONAL | Number formatting style | | searchCountryField | SearchCountryField[] | [SearchCountryField.NAME] | Fields to include in country search | | phoneValidation | boolean | true | Enable/disable number validation | | selectedCountryISO | CountryISO | - |