1.2.4 • Published 5 months ago

ngx-intl-phone-number v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Intro

This library is for International Phone Number Validation for Angular using Directive. Based on that project. It supports both Template driven and Reactive Forms.

libphonenumber-js is used for the Phone Number validation.

Demo

Usage

  1. npm i ngx-intl-phone-number

  2. Add NgxIntlPhoneNumberModule import to your NgModule like this:

    import { NgxIntlPhoneNumberModule } from "ngx-intl-phone-number";
    
    @NgModule({
      imports: [NgxIntlPhoneNumberModule],
    })
    export class AuthModule {}
  3. Add the Directive to you Phone Number Input like this:

    <input
     type="tel"
     formControlName="phoneNumber"
     intl-phone-number
     defaultCountry="PL"
     (countrySelected)="countryChanged($event)"/>

Inputs

NameTypeDefaultDescription
searchablebooleantrueAllow to search for country
searchPlaceHolderstring?nullThe Placeholder for the search input
defaultCountrystring?nullAlpha 2 Country Code
onlyCountriesstring[]?[]List of manually selected countries, which will appear in the dropdown
separateDialCodebooleanfalseUse to display dial code next to the flag
strictValidationbooleanfalseIf true, it also validates the actual phone number digits

Outputs

NameParametersDescription
countrySelectedcountry: CountryEmits whenever there is a change in country selected including the default country
dropdownOpeneddidOpen: booleanEmits whenever dropdown is toggled

Styling

  • dropdown-open class is added on the root element of country select when dropdown is open for custom styling

Sources

The Countries Data was copied form this Github Repo