简体   繁体   中英

ERROR TypeError: a.getCountryCodeOrDefault is not a function

I'm trying to use google-libphonenumber package in an Angular project for validating phone number

import { PhoneNumberUtil } from 'google-libphonenumber';

  public phoneUtil = PhoneNumberUtil.getInstance();

  phoneUtil.isValidNumber('+919421013328');

but it gives me

TypeError: a.getCountryCodeOrDefault is not a function.

can someone please help me with this??

From the google-libphonenumber package readme :

Most libphonenumber functions expect to receive an instance of libphonenumber.PhoneNumber which can be obtained by calling phoneUtil.parse or phoneUtil.parseAndKeepRawInput on a raw (string) number, otherwise it will throw errors like TypeError: a.getCountryCodeOrDefault is not a function.

phoneUtil.isValidNumberForRegion(phoneUtil.parse('202-456-1414', 'US'), 'US');

or if you have multiple country codes:

phoneUtil.parseAndKeepRawInput('+919421013329');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM