We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I get an additional 0 in the phone mask when using 44 code with PhoneNumberFormat.NATIONAL only.
The result:
import { PhoneNumberUtil, PhoneNumberFormat } from 'google-libphonenumber'
import { PhoneValidator } from '@/app/presentation/common/protocols' import { PhoneFormatter } from '@/app/presentation/common/protocols/phone-formatter'
export class GooglePhoneFormatter implements PhoneFormatter, PhoneValidator { constructor ( private readonly phoneNumberFormat: PhoneNumberUtil = PhoneNumberUtil.getInstance() ) {}
validate (phoneNumber: string, countryCode: string): boolean { if (!phoneNumber) return true try { const parsedNumber = this.phoneNumberFormat.parseAndKeepRawInput( phoneNumber, countryCode )
return this.phoneNumberFormat.isValidNumber(parsedNumber) } catch (error) { console.error(error) return false }
}
format (countryCode: string, phoneNumber: string): string { if (!phoneNumber) return '' try { const parsedNumber = this.phoneNumberFormat.parseAndKeepRawInput( phoneNumber, countryCode )
const formattedNumber = this.phoneNumberFormat.format( parsedNumber, PhoneNumberFormat.NATIONAL ) return formattedNumber } catch (error) { console.error(error) return phoneNumber }
} }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I get an additional 0 in the phone mask when using 44 code with PhoneNumberFormat.NATIONAL only.
The result:
import { PhoneNumberUtil, PhoneNumberFormat } from 'google-libphonenumber'
import { PhoneValidator } from '@/app/presentation/common/protocols'
import { PhoneFormatter } from '@/app/presentation/common/protocols/phone-formatter'
export class GooglePhoneFormatter implements PhoneFormatter, PhoneValidator {
constructor (
private readonly phoneNumberFormat: PhoneNumberUtil = PhoneNumberUtil.getInstance()
) {}
validate (phoneNumber: string, countryCode: string): boolean {
if (!phoneNumber) return true
try {
const parsedNumber = this.phoneNumberFormat.parseAndKeepRawInput(
phoneNumber,
countryCode
)
}
format (countryCode: string, phoneNumber: string): string {
if (!phoneNumber) return ''
try {
const parsedNumber = this.phoneNumberFormat.parseAndKeepRawInput(
phoneNumber,
countryCode
)
}
}
The text was updated successfully, but these errors were encountered: