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 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');
or if you have multiple country codes:
phoneUtil.parseAndKeepRawInput('+919421013329');