An Ionic component for International Phone Number Input, that allows all countries, validation with google phone lib, limited countries, preferred countries, virtual scrolling and much more.
npm install ion-intl-tel-inputAn Ionic component for International Phone Number Input, that allows all countries, validation with google phone lib, limited countries, preferred countries, virtual scrolling and much more.
- Ionic 4 (>=4.0.0)
npm install ion-intl-tel-input --save
`#### Or Install with All dependencies
`
npm install ion-intl-tel-input ionic-selectable flag-icon-css google-libphonenumber --save
`#### Add flag styles
Add the following to your
styles array of project in angular.json (located in projects root directory).
`
{
"input": "node_modules/flag-icon-css/sass/flag-icon.scss"
}
`$3
First, import
IsIonIntlTelInputModule to your app.module.ts that is normally located in src\app\app.module.ts.`
import { IonIntlTelInputModule } from 'ion-intl-tel-input';@NgModule({
imports: [
IonIntlTelInputModule
]
})
export class AppModule { }
`Note: Additionally, if you are using lazy loaded pages. Check if your pages have a module file, for example,
home.module.ts, and if they do then import IsIonIntlTelInputModule to each page module too.`
import { IonIntlTelInputModule } from 'ionic-selectable';
import { HomePage } from './home';@NgModule({
declarations: [
HomePage
],
imports: [
IonicPageModule.forChild(HomePage),
IonIntlTelInputModule
]
})
export class HomePageModule { }
`$3
#### a. Usage with Template Driven Forms
`
`#### b. Usage with Reactive Forms
`
`$3
#### a. Usage with Template Driven Forms
`
@Component({ ... })
export class HomePage { phoneNumber = '';
constructor() { }
}
`#### b. Usage with Reactive Forms
`@Component({ ... })
export class HomePage implements OnInit {
formValue = {phoneNumber: '', test: ''};
form: FormGroup;
constructor() { }
ngOnInit() {
this.form = new FormGroup({
phoneNumber: new FormControl({
value: this.formValue.phoneNumber
})
});
}
get phoneNumber() { return this.form.get('phoneNumber'); }
onSubmit() {
console.log(this.phoneNumber.value);
}
}
`$3
#### a. Usage with Template Driven Forms
`
`#### b. Usage with Reactive Forms
`
`$3
#### a. Usage with Template Driven Forms
`
@Component({ ... })
export class HomePage { phoneNumber = '';
constructor() { }
}
`#### b. Usage with Reactive Forms
`
import { IonIntlTelInputValidators } from 'is-ion-intl-tel-input';@Component({ ... })
export class HomePage implements OnInit {
formValue = {phoneNumber: '', test: ''};
form: FormGroup;
constructor() { }
ngOnInit() {
this.form = new FormGroup({
phoneNumber: new FormControl({
value: this.formValue.phoneNumber
}, [
Validators.required,
IonIntlTelInputValidators.phone
])
});
}
get phoneNumber() { return this.form.get('phoneNumber'); }
onSubmit() {
console.log(this.phoneNumber.value);
}
}
`Options
| Option | Type | Default | Description |
| ------------------------- | -------- | ------- | ----------- |
| defaultCountryiso | string | NULL | Iso Code of default selected Country. |
| dialCodePrefix | string | + | Determines whether to use
00 or + as dial code prefix. Available attributes are + and 00. |
| enableAutoCountrySelect | boolean | false | Determines whether to select automatic country based on user input. |
| enablePlaceholder | boolean | true | Determines whether an example number will be shown as a placeholder in input. |
| fallbackPlaceholder | string | NULL | A fallaback placeholder to be used if no example number is found for a country. |
| inputPlaceholder | string | NULL | If a custom placeholder is needed for input. If this property is set it will override enablePlaceholderand only this placeholder will be shown. |
| maxLength | string | 15 | Maximum Length for input. |
| modalTitle | string | Select Country | Title of modal opened to select country dial code. |
| modalCssClass | string | NULL | CSS class to attach to dial code selection modal. |
| modalSearchPlaceholder | string | Enter country name | Placeholder for input in dial code selection modal. |
| modalCloseText | string | Close | Text for close button in dial code selection modal. |
| modalCloseButtonSlot | string | end | Slot for close button in dial code selection modal. Ionic slots are supported. |
| modalCanSearch | boolean | true | Determines whether dial code selection modal should be searchable or not. |
| modalShouldBackdropClose | boolean | true | Determines whether dial code selection modal is closed on backdrop click. |
| modalShouldFocusSearchbar | boolean | true | Determines whether input should be focused when dial code selection modal is opened. |
| modalSearchFailText | string | No countries found | Determines whether input should be focused when dial code selection modal is opened. |
| onlyCountries | string[] | [] | List of iso codes of manually selected countries as string, which will appear in the dropdown. Note: onlyCountries should be a string array of country iso codes. |
| preferredCountries | string[] | [] | List of iso codes as string of countries, which will appear at the top in dial code selection modal. Note: preferredCountries should be a string array of country iso codes.
| selectFirstCountry | boolean | true | Determines whether first country should be selected in dial code select or not. |
| separateDialCode | boolean | true | Determines whether to visually separate dialcode into the drop down element. |Events
| Event Name | Type | Description |
| -------------- | ------------------- | ----------- |
| numberChange |
EventEmitter | Fires when the Phone number Input is changed. |
| numberBlur | EventEmitter | Fires when the Phone number Input is blurred. |
| numberFocus | EventEmitter | Fires when the Phone number Input is focused. |
| numberInput | EventEmitter | Fires when the user is typing in Phone number Input. |
| codeChange | EventEmitter | Fires when the dial code selection is changed. |
| codeOpen | EventEmitter | Fires when the dial code selection modal is opened. |
| codeClose | EventEmitter | Fires when the dial code selection modal is closed. |
| codeSelect | EventEmitterThis project follows the all-contributors specification. Contributions of any kind welcome!
We use SemVer for versioning.
Azzam Asghar - Initial work* - Azzam Asghar
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details
This project would never have been possible without the following great plugins:
* Ionic Selectable by @eakoriakin
* International Telephone Input for Angular (NgxIntlTelInput) by @webcat12345
* flag-icon-css by @lipis
So please do go ahead and give them a star for their efforts.