Forked from (https://github.com/webcat12345/ngx-intl-tel-input)
-
Replace the use of google-libphonenumber with libphonenumber-js. (this library has smaller size).
- projects/ngx-intl-tel-input/package.json
- projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts
- projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.component.ts
-
Previously, the phone validation was done by passing
phoneValidation (boolean)
, now the validator has been exported separately and can be used as required- projects/ngx-intl-tel-input/src/public_api.ts
- projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.validator.ts
-
The field got marked as dirty when the phone number was passed to it after it was initialized (e.g. after API response. The field will now be marked pristine if
markPristineOnExternalChange
is set totrue
. -
Country list got jumbled up as indicated in webcat12345#396. The fix was webcat12345#400
-
It was upgraded to work with angular-12
- angular.json
- package.json
- src/polyfills.ts
- tsconfig.json
- src/test.ts
- src/environments/environment.ts
-
In order create a dual field supporting email and mobile phone, we added a parameter
allowedChars
which can be passed to it so it can accept other characters as well instead of just ignoring them.- projects/ngx-intl-tel-input/src/lib/ngx-intl-tel-input.component.ts
-
Added country code 246
An Angular package for entering and validating international telephone numbers. It adds a flag dropdown to any input, detects the user's country, displays a relevant placeholder and provides formatting/validation methods.
Compatibility:
Validation with libphonenumber-js
ngx-intl-tel-input | Angular | ngx-bootstrap |
---|---|---|
3.x.x | 9.x.x - 12.x.x | 6.0.0 |
2.x.x | 8.x.x - 9.1.x | 5.6.x |
$ npm install [email protected] --save
$ npm install libphonenumber-js --save
$ ng add ngx-bootstrap
If you do not wish to use Bootstrap's global CSS, we now package the project with only the relevant
bootstrap styling needed for the dropdown. As such, you can remove the bootstrap styling from angular.json
.
Further, Angular CLI should tree-shake the rest of Ngx-Boostrap away if you don't utilize other dependencies from the bootstrap package. This should keep this dependency a lean feature-add
Add 'intl-tel-input' style file:
./node_modules/intl-tel-input/build/css/intlTelInput.css
to angular.json styles array:
"styles": [
"./node_modules/intl-tel-input/build/css/intlTelInput.css",
"src/styles.css"
],
$ npm install ngx-intl-tel-input --save
Add NgxIntlTelInputModule
to your module file:
imports: [NgxIntlTelInputModule];
Refer to main app in this repository for working example.
<form #f="ngForm" [formGroup]="phoneForm">
<ngx-intl-tel-input
[cssClass]="'custom'"
[preferredCountries]="[CountryISO.UnitedStates, CountryISO.UnitedKingdom]"
[enableAutoCountrySelect]="false"
[enablePlaceholder]="true"
[searchCountryFlag]="true"
[searchCountryField]="[SearchCountryField.Iso2, SearchCountryField.Name]"
[selectFirstCountry]="false"
[selectedCountryISO]="CountryISO.India"
[maxLength]="15"
[inputId]="my-input-id"
name="phone"
formControlName="phone"
></ngx-intl-tel-input>
</form>
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 |
true |
Toggle automatic country (flag) selection based on user input. |
enablePlaceholder | boolean |
true |
Input placeholder text, which adapts to the country selected. |
customPlaceholder | string |
None |
Custom string to be inserted as a placeholder. |
numberFormat | <PhoneNumberFormat> |
PhoneNumberFormat.International |
Custom string to be inserted as a placeholder. |
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. |
selectFirstCountry | boolean |
true |
Selects first country from preferredCountries if is set. If not then uses main list. |
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. |
Following formats are supported
- NATIONAL // Produces "044 668 18 00"
- INTERNATIONAL // Produces "+41 44 668 18 00"
- E164 // Produces "+41446681800"
- Build lib:
$ npm run build_lib
- Copy license and readme files:
$ npm run copy-files
- Create package:
$ npm run npm_pack
- Build lib and create package:
$ npm run package
After building and creating package, you can use it locally too.
In your project run:
$ npm install --save {{path to your local '*.tgz' package file}}
Before you can start using the package with the latest changes, you need to publish the package to NPM with a new version. To publish a new version of the package:
- Go to
projects/ngx-intl-tel-input
and bump theversion
number in thepackage.json
file. - Run
npm run package
in the root directory - Go to
dist/ngx-splide
- Login to Cialfo NPM account using
npm adduser
command (find credentials in vault) - Run
npm publish --access public
- Go the NPM page of the package https://www.npmjs.com/package/@cialfo/ngx-intl-tel-input to verify the latest version is published.
- update the version of the
ngx-intl-tel-input
package in thepackage.json
file of the project where the library is used and do annpm install
.