0

I'm using PhoneNumberKit to validate phone numbers but it returns invalid results for my test cases.

let phoneNumberKit = PhoneNumberKit()
do {
    let parsedNumber = try phoneNumberKit.parse(phoneNumber, ignoreType: true)
    return ""
} catch {
    return "\(error.localizedDescription)"
}

Input - +0424466934 / Expected(link) : Invalid country calling code / Actual : No error

Input - +6133333 / Expected : No error / Actual : The number provided is invalid

I want to match the validations with google libphonenumber. Any idea why or how to achieve this?

ajw
  • 2,568
  • 23
  • 27
  • Why do you expect no error for "+613333"? That is not a valid Australian number "+61133333" is valid – Paulw11 Aug 29 '23 at 09:50
  • When I use phone number kit to parse `+0424466934` it throws an `invalidNumber` exception. – Paulw11 Aug 29 '23 at 10:01
  • Hey @Paulw11, What about for +6133333 ? I have missed one number there. That returns as a valid number in google libphonenumber. – ajw Aug 30 '23 at 01:03
  • I'm using PhoneNumberKit 3.6.7 – ajw Aug 30 '23 at 03:46
  • 1
    Then libphonenumber is incorrect. +6133333 is not a valid Australian number - If you convert that back to national number format it would be 03 3333 - This is not a valid Australian number. As I said, 13 3333 is a valid Australian number- that would be +61133333. Your [test site](https://htmlpreview.github.io/?https://github.com/google/libphonenumber/blob/master/javascript/i18n/phonenumbers/demo-compiled.html) says that `+6133333` is invalid. – Paulw11 Aug 30 '23 at 04:12
  • Yes, you are right. +0424466934 returns invalidNumber instead of Invalid country calling code. Which one should be correct for that? – ajw Aug 30 '23 at 05:59
  • 1
    Looking at the code, `invalidNumber` is correct. The `invalidCountryCode` exception is only thrown if the region you pass to `parse` is not valid. https://github.com/marmelroy/PhoneNumberKit/blob/9634306b10ab65a75524f89739b33f6dd26d7991/PhoneNumberKit/ParseManager.swift#L49 – Paulw11 Aug 30 '23 at 08:07

0 Answers0