ERROR TypeError: a.getCountryCodeOrDefault is not a function
ERROR TypeError: a.getCountryCodeOrDefault is not a function
我正在尝试在 Angular 项目中使用 google-libphonenumber
包来验证 phone 数字
import { PhoneNumberUtil } from 'google-libphonenumber';
public phoneUtil = PhoneNumberUtil.getInstance();
phoneUtil.isValidNumber('+919421013328');
但它给了我
TypeError: a.getCountryCodeOrDefault is not a function.
有人可以帮我解决这个问题吗?
来自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');
或者如果您有多个国家代码:
phoneUtil.parseAndKeepRawInput('+919421013329');
我正在尝试在 Angular 项目中使用 google-libphonenumber
包来验证 phone 数字
import { PhoneNumberUtil } from 'google-libphonenumber';
public phoneUtil = PhoneNumberUtil.getInstance();
phoneUtil.isValidNumber('+919421013328');
但它给了我
TypeError: a.getCountryCodeOrDefault is not a function.
有人可以帮我解决这个问题吗?
来自the google-libphonenumber package readme:
Most
libphonenumber
functions expect to receive an instance oflibphonenumber.PhoneNumber
which can be obtained by callingphoneUtil.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');
或者如果您有多个国家代码:
phoneUtil.parseAndKeepRawInput('+919421013329');