AngularJS - Phone Number Input
An AngularJS package for entering and validating international telephone numbers. It also adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting / validation methods.
Table of contents
- Supports
- Demo
- Install Dependencies
- Add Dependency Style
- Usage
- Example
- Options
- Methods
- Supported Formats
- Want to Contribute?
- Collection of Components
- Changelog
- Credits
- License
- Keywords
Supports:
- Angular 8
- Angular 9
- ReactiveFormsModule
- FormsModule
- Validation with google-libphonenumber
Demo
Install Dependencies
$ npm install angular-weblineindia-phone-number --save
$ npm install google-libphonenumber --save
$ ng add ngx-bootstrap
Add Dependency Style
Add 'angular-weblineindia-phone-number' style file:
./node_modules/angular-weblineindia-phone-number/build/css/intlTelInput.css
to angular.json styles array:
"styles": ,
Install This Library
$ npm install angular-weblineindia-phone-number --save
Usage
Add BsDropDownModule
and PhoneModule
to your module file:
; imports: BsDropdownModule PhoneModule;
Example
;
Options
Options | Type | Default | Description |
---|---|---|---|
cssClass | string |
control-form |
Bootstrap input css class or your own custom one. |
preferredCountries | <CountryISO>[] |
[] |
List of countries, which will appear at the top. |
onlyCountries | <CountryISO>[] |
[] |
List of manually selected countries, which will appear in the dropdown. |
enableAutoCountrySelect | boolean |
false |
Toggle automatic country (flag) selection based on user input. |
enablePlaceholder | boolean |
true |
Input placeholder text, which addapts to the country selected. |
searchCountryFlag | boolean |
false |
Enables input search box for countries in the flag dropdown. |
searchCountryField | <SearchCountryField>[] |
[SearchCountryField.All] |
Customize which fields to search in, if searchCountryFlag is enabled. Use SearchCountryField helper enum. |
searchCountryPlaceholder | string |
'Search Country' |
Placeholder value for searchCountryField |
maxLength | number |
None |
Add character limit. |
tooltipField | <TooltipLabel> |
None |
Set tooltip on flag hover. Use TooltipLabel helper enum for label type options. |
selectFirstCountry | boolean |
true |
Selects first country from preferredCountries if is set. If not then uses main list. |
phoneValidation | boolean |
true |
Disable phone validation. |
inputId | string |
phone |
Unique ID for <input> element. |
selectedCountryISO | <CountryISO> |
None |
Set specific country on load. |
separateDialCode | boolean |
false |
Visually separate dialcode into the drop down element. |
countryChange | <Country> |
None |
Emits country value when the user selects a country from the dropdown. |
phoneValidationErrorMsg | string |
default phone validation error message | |
phoneUniqueErrorMsg | string |
default phone unique error message | |
maxLength | number |
15 | default phone maxlength |
isMultiple | boolean |
true | for add multiple phone number |
Methods
Name | Description |
---|---|
onMultiple | Gets triggered when click on plus icon. |
change | Gets triggered every time input got changed. |
Supported Formats
Following formats are supported
- NATIONAL // Produces "044 668 18 00"
- INTERNATIONAL // Produces "+41 44 668 18 00"
- E164 // Produces "+41446681800"
Want to Contribute?
- Created something awesome, made this code better, added some functionality, or whatever (this is the hardest part).
- Fork it.
- Create new branch to contribute your changes.
- Commit all your changes to your branch.
- Submit a pull request.
Collection of Components
We have built many other components and free resources for software development in various programming languages. Kindly click here to view our Free Resources for Software Development
Changelog
Detailed changes for each release are documented in CHANGELOG.md.
Credits
angular-weblineindia-phone-number is inspired by the ngx-intl-tel-input.
License
Keywords
angularjs, angular-weblineindia-phone-number, phone-number-validation, angular-phonenumber-input, phone-number-input, phone-input-class, international-telephone-input, telephone-input