Open fwitkowski opened 2 years ago
@fwitkowski Did you find any workaround for this?
I also need to save e164Number
only as string in my database
try this
import * as lpn from 'google-libphonenumber';
const PNF = lpn.PhoneNumberFormat;
/* const phoneUtil = require('google-libphonenumber').PhoneNumberUtil.getInstance();*/
//e164NumberFromDb is the e164Number from your database const phoneNumber = this.phoneUtil.parseAndKeepRawInput(e164NumberFromDb);
const phone= {
"number":phoneNumber.getNationalNumber(),
"internationalNumber": this.phoneUtil.format(phoneNumber, PNF.INTERNATIONAL),
"nationalNumber": this.phoneUtil.format(phoneNumber, PNF.NATIONAL),
"e164Number": this.phoneUtil.format(phoneNumber, PNF.E164),
"countryCode": this.phoneUtil.getRegionCodeForNumber(phoneNumber),
"dialCode": '+' +phoneNumber.getCountryCode()
}
console.log(phone);
In my project I am using ngx-intl-tel-input for international phone numbers. When user sets value it has this format (ChangeData interface):
I want to save to database only e164Number, which is no issue. The issue is when I want to convert it back to ChangeData object.
The plugin does not provide public function to do this; at least I cannot find one.
I see that original library (JS): intl-tel-input has a public function setNumber, see in package documentation, however I cannot find a way to user that directly in Angular.