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

ngx-mat-tel-input

v2.1.0

Published

Angular Material component for inputting telephone numbers.

Downloads

238

Readme

NgxMatTelInput

Angular Material component for inputting telephone numbers.

  • Validates and formats phone numbers (via Google's libphonenumber)
  • Material design
  • Reactive forms
  • 250 countries and dependent areas
  • Flags optimized for low resolution
  • Angular 8, 9, 10, 11, 12

Click here to see a StackBlitz demo.

Installation

Install peer dependencies:

$ npm install @angular/flex-layout ngx-mat-select-search google-libphonenumber world-countries

Install the package using npm:

$ npm install ngx-mat-tel-input

Note: If you're running npm 7.0.0 or later, add --legacy-peer-deps

Import the module into your app.module.ts:

import { NgxMatTelInputModule } from 'ngx-mat-tel-input';

@NgModule({
  ...
  imports: [
    ...,
    NgxMatTelInputModule
  ],
  ...
})

Basic Usage

Template

<form [formGroup]="myFormGroup" (ngSubmit)="onSubmit()" autocomplete="off">
  <mat-form-field appearance="outline">
    <mat-label>Phone Number</mat-label>
    <lib-ngx-mat-tel-input formControlName="phoneNumber">
    </lib-ngx-mat-tel-input>
    <mat-error *ngIf="phoneNumber.hasError('required')">
      This field is <strong>required</strong>
    </mat-error>
    <mat-error *ngIf="phoneNumber.hasError('format')">
      Phone number is <strong>invalid</strong>
    </mat-error>
  </mat-form-field>
</form>

Component

import {Component} from '@angular/core';

import {FormGroup, FormControl, Validators} from '@angular/forms';

@Component({
  selector: 'my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent { 
  myFormGroup = new FormGroup({
    phoneNumber: new FormControl({value: '', disabled: false}, [Validators.required,]),
  });

  onSubmit(): void {

  }

  get phoneNumber(): FormControl {
    return this.myFormGroup.get('phoneNumber') as FormControl;
  }

}

Errors

format

This error is triggered when the user's input does not form a valid phone number.

  <mat-error *ngIf="phoneNumber.hasError('format')">
    Phone number is <strong>invalid</strong>
  </mat-error>

country

This error is triggered when the user enters a phone number which belongs to a country or dependent area that isn't in countryWhiteList, or is in countryBlacklist.

  <mat-error *ngIf="phoneNumber.hasError('country')">
    US numbers <strong>only</strong>
  </mat-error>

Options

| Option | Type | Optional? | Example | Description | |------------------|------------|-----------|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | defaultCountry | string | Yes | [defaultCountry]="'US'" | The country or dependent area to be selected by default in the country picker. If omitted, Afghanistan will be selected by default. | | countryWhitelist | string[] | Yes | [countryWhitelist]="['US', 'CA']" | List of countries and dependent areas to include in the country picker. If omitted, all countries and dependant areas will be displayed. | | countryBlacklist | string[] | Yes | [countryBlacklist]="['DE','PA','NZ']" | List of countries and dependent areas to exclude from the country picker. If omitted, all countries and dependant areas will be displayed. | | format | number | Yes | [format]="0" | The format of the phone number written to form control bound to lib-ngx-mat-tel-input.0 - E164 (Default)1 - INTERNATIONAL2 - NATIONAL3 - RFC3966 |


NOTE

Countries are represented by their ISO 3166-1 alpha-2 code (e.g. " FR" for France). Codes should consist of capital letters only with no extraneous whitespace.