Edited (15.03.2018) - thanks @Joseph Webber
First, you have to install libphonenumber-js, which is a wrapper of google-libphonenumber ready to be imported on Angular 2+. You can install it on your app with:
npm install libphonenumber-js --save
or
yarn add libphonenumber-js
depending on the package manager you use.
After install you can use it on your component like:
import { Component, OnInit } from '@angular/core';
import { parse, format, AsYouType } from 'libphonenumber-js';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
asYouType: any;
format: any;
parse: any;
ngOnInit() {
this.asYouType = new AsYouType('US').input('2133734');
this.format = format('2133734253', 'US', 'International');
this.parse = parse('(0777) 844 822', 'RO');
}
}
I added the working demo on Github:
libphonenumber-demo-angular2
Answer from BogdanC on Stack Overflownpm
npmjs.com › package › angular-libphonenumber
angular-libphonenumber - npm
March 18, 2016 - angular-libphonenumber is an angular directive that can be used as an input mask. By default, all numbers are formatted in US format, but the format can be set with the country-code descriptor.
» npm install angular-libphonenumber
Published Mar 18, 2016
Version 1.1.0
Author Cameron Will
npm
npmjs.com › package › libphonenumber-js
libphonenumber-js - npm
1 week ago - A simpler (and smaller) rewrite of Google Android's libphonenumber library in javascript. Latest version: 1.12.41, last published: 5 days ago. Start using libphonenumber-js in your project by running `npm i libphonenumber-js`. There are 3934 ...
» npm install libphonenumber-js
Published Mar 28, 2026
Version 1.12.41
Author catamphetamine
GitHub
github.com › cwill747 › angular-libphonenumber
GitHub - cwill747/angular-libphonenumber: nathanhammond/libphonenumber as an angular input mask
September 20, 2021 - angular-libphonenumber is an angular directive that can be used as an input mask. By default, all numbers are formatted in US format, but the format can be set with the country-code descriptor.
Starred by 40 users
Forked by 28 users
Languages JavaScript 100.0% | JavaScript 100.0%
Medium
medium.com › @intheskyp › angular-bundle-optimisation-making-old-external-libraries-treeshakable-db391829f94b
Angular bundle optimisation. Making old external libraries “treeshakable”. | by Yehor Yakymenko | Medium
December 27, 2024 - import { PhoneNumberUtil, PhoneNumber } from 'google-libphonenumber'; @Injectable({ providedIn: 'root', // Makes this service tree-shakable and singleton }) export class LibphoneService { private libPhoneInstance: PhoneNumberUtil; constructor() { // Lazy load the dependency to minimize the initial bundle size // Constructor won't be triggered until this class will be initialized // by DI mechanism in place where this class it used this.loadLibPhoneInstance(); } // .... // Interlal service code // .... private async loadLibPhoneInstance(): Promise<void> { if (!this.libPhoneInstance) { const { P
Plunker
embed.plnkr.co › DOzjJXGAbdlQVSHa2ij6
international phone number angular component demo - Plunker
# (international phone number)[https://github.com/mareczek/international-phone-number] angular component demo · /** * Follow instructions here to compile this file: * https://github.com/googlei18n/libphonenumber/blob/master/javascript/README * * Once setup, to re-compile: * 1) Copy the contents of this file into libphonenumber/javascript/i18n/phonenumbers/demo.js * 2) ant -f libphonenumber/javascript/build.xml compile-demo * 3) Copy libphonenumber/javascript/i18n/phonenumbers/demo-compiled.js to intl-tel-input/lib/libphonenumber/build/utils.js */ // includes goog.require('i18n.phonenumbers.As
Catamphetamine
catamphetamine.github.io › libphonenumber-js
libphonenumber-js
A simpler and smaller rewrite of Google Android's libphonenumber library.
GitHub
github.com › eraycetinay › ng-valid-phone
GitHub - eraycetinay/ng-valid-phone: Angularjs directive which use google's libphonenumber library for international phone number validations.
Angularjs directive which use google's libphonenumber library for international phone number validations. npm install ng-valid-phone bower install ng-valid-phone · International number validation.
Starred by 6 users
Forked by 3 users
Google Groups
groups.google.com › g › libphonenumber-discuss › c › hjGyHnO-kIg
libphonenumber javascript with angular.js
January 29, 2014 - libphonenumber depends on closure, so there is no easy way to get around that. However, if you don't need the asyoutypeformatter, you can just use phonenumberutil.js directly, which doesn't depend on the asyoutypeformatter.
npm
npmjs.com › search
libphonenumber-js - npm search
Wrapper around libphonenumber-js to provide RingCentral specific phone handling. embbnux• 1.2.0 • 2 months ago • 1 dependents • MITpublished version 1.2.0, 2 months ago1 dependents licensed under $MIT ...
Snyk
snyk.io › advisor › google-libphonenumber › google-libphonenumber code examples
Top 5 google-libphonenumber Code Examples | Snyk
// SPDX-License-Identifier: MIT import { FormControl } from '@angular/forms'; declare var require: any; var phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance(); export class PhoneNumberValidator { static isValid(control: FormControl): any { let number = control.value; let phoneProto; if(number == null || number == '') { return null; } let countryCode = 'US'; if(number.charAt(0)==='+') { countryCode = 'ZZ'; } The up-to-date and reliable Google's libphonenumber package for node.js.
Npm
npm.io › search › keyword:libphonenumber
Libphonenumber | npm.io
angularphoneformatformatterlib...torvalidationparse1.172.0 • Published 10 months ago · JavaScript port of Google's libphonenumber library for parsing, formatting, and validating international phone numbers in Node.js......