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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-dial-input

v2.1.4

Published

Angular phone input component with country selector, dial code support, and min/max length validation.

Readme

PhoneInputComponent

A powerful Angular phone input component with international country selection, automatic formatting, and validation.

Part of ngx-dial-input library. See main README for general information.

Component Inputs

| Input | Type | Default | Description | |-------|------|---------|-------------| | defaultCountry | string | '' | ISO 2-letter country code (e.g., 'US', 'GB', 'IN') | | placeholder | string | '' | Placeholder text in the phone input field | | searchEnabled | boolean | true | Enable/disable country search in dropdown | | numberFormat | 'international' \| 'national' | 'international' | Phone number format: +12015551234 (international) or 2015551234 (national) | | setFirstCountry | string | '' | Pre-select a specific country |

Component Output

phoneChange Event

Emitted when phone value changes:

interface PhoneData {
  e164Number: string;       // '+12015551234' - International format for storage
  nationalNumber: string;   // '2015551234'   - Just the digits
  dialCode: string;         // '+1'           - Country dial code
  countryCode: string;      // 'us'           - ISO 2-letter code (lowercase)
  isValid: boolean;         // true/false     - Validation status
}

Usage Example

Reactive Forms

import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { PhoneInputModule } from 'ngx-dial-input';

@Component({
  selector: 'app-contact-form',
  template: `
    <form [formGroup]="form" (ngSubmit)="submit()">
      <div class="form-group">
        <label>Phone Number</label>
        <phone-input
          [defaultCountry]="'US'"
          [placeholder]="'Enter phone number'"
          [searchEnabled]="true"
          formControlName="phone"
          (phoneChange)="onPhoneChange($event)">
        </phone-input>
        <small *ngIf="form.get('phone').invalid && form.get('phone').touched">
          Please enter a valid phone number
        </small>
      </div>
      <button type="submit" [disabled]="form.invalid">Submit</button>
    </form>
  `,
  standalone: false
})
export class ContactFormComponent {
  form: FormGroup;

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

  onPhoneChange(data: any) {
    if (data.isValid) {
      console.log('Valid phone (e164):', data.e164Number);
    }
  }

  submit() {
    const phoneData = this.form.get('phone').value;
    console.log('Phone to save:', phoneData.e164Number);
    // API call to save phone
  }
}

With Default Country

<phone-input
  [defaultCountry]="'GB'"
  [setFirstCountry]="'GB'"
  [numberFormat]="'national'"
  formControlName="phone">
</phone-input>

Validation Behavior

Empty Input

  • Initial state with no input: isValid = false (but no validation error)
  • Allows users to leave the field empty until they start typing

Partial Input

  • Once user starts typing, validates against country's minimum length
  • Phone with insufficient digits: isValid = false

Complete Input

  • Phone matching country's required length: isValid = true
  • Phone exceeding max length: isValid = false

Length Rules Used by the Component

  • Validation checks minLength and maxLength from each country entry.
  • phoneLength remains in the data model as a compatibility/reference field.
  • Current runtime validity decisions are not based on phoneLength.

Syria Example

Country: Syria (min: 9 digits, max: 10 digits)
- 8 digits: isValid = false
- 9 digits: isValid = true
- 10 digits: isValid = true
- 11 digits: isValid = false

Example

Country: United States (min: 10 digits, max: 10 digits)
- Empty (no input): isValid = false, no error
- Entering: '201' (3 digits): isValid = false, too short
- Complete: '2015551234' (10 digits): isValid = true
- Excess: '20155512345' (11 digits): isValid = false, too long

Supported Features

200+ Countries with:

  • Dial codes
  • Flag images
  • Min/max phone length
  • Format patterns

Smart Search

  • Search by country name
  • Case-insensitive matching
  • Fast filtering

Animations

  • Smooth dropdown open/close
  • Responsive to user interactions

Keyboard Support

  • Arrow keys to navigate
  • Enter to select
  • Escape to close dropdown

ControlValueAccessor

  • Works with formControlName
  • Works with [(ngModel)]
  • Works with Reactive Forms and Template Forms

Building & Testing

# Build the library
ng build phone-input

# Run unit tests
ng test phone-input --watch

# Run tests (CI mode, no watch)
ng test phone-input --watch=false --browsers=ChromeHeadless

# Create distributable package
npm run build

Output Structure

After building:

dist/
  phone-input/
    lib/
      phone-input.component.d.ts
      phone-input.module.d.ts
    package.json
    README.md
    LICENSE
    phone-input.d.ts  (public API)

Browser Compatibility

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

Performance

  • Component uses OnPush change detection
  • Optimized country list filtering
  • Minimal re-renders

Accessibility

  • Semantic HTML structure
  • Keyboard navigation support
  • ARIA labels on country selector

Contributing

Issues and PRs are welcome on GitHub

License

MIT © CroemInc