import { Injectable } from '@angular/core' ; import * as phonenumbers from 'google-libphonenumber' ; @ Injectable ( ) export class PhoneNumberValidationProvider { constructor ( ) { } public isValidMobile ( _phonenumber , country ) { try { const phoneUtil = phonenumbers . PhoneNumberUtil . getInstance ( ) ; const phoneNumber = phoneUtil . parse ( _phonenumber , country ) ; const isValid = phoneUtil . isValidNumber ( phoneNumber ) ; const numberType = phoneUtil . getNumberType ( phoneNumber ) ; const isMobile = numberType === phonenumbers . PhoneNumberType . MOBILE || numberType === phonenumbers . PhoneNumberType . FIXED_LINE_OR_MOBILE ; if ( isValid && isMobile ) { return true ; } } catch ( e ) { console . error ( e ) ; } return false ; } }