marmelroy / PhoneNumberKit

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
MIT License
5.1k stars 810 forks source link

Unable to parse czech numbers from string #759

Closed eduard-cihunka closed 2 months ago

eduard-cihunka commented 5 months ago

New Issue Checklist

Steps to reproduce

I'm trying to parse phone number from string 420777666555 with parse function phoneNumberKit.parse(phoneNumber.fullPhoneNumber) where phoneNumberKit is private let phoneNumberKit = PhoneNumberKit(). On Version 3.5.10 everything works fine, after update to newest version I'm not able to parse czech republic numbers from string. We need to update to newest version because of apple privacy manifest. From my observations function func hasValue(_ value: String?) -> Bool returns different values after update, so maybe the issue could be there.

Test examples

Screenshot 2024-04-09 at 13 38 25

For better understanding, format is our internal implementation, just maps our internal format to the library one, but fail occurs on the first line where PhoneNumberKit trying to parse number from string.

Screenshot 2024-04-09 at 13 39 22

Expected result

Parsed PhoneNumber struct

Actual result

Parsing fail and result is nil

Environment

SPM

bguidolim commented 5 months ago

Hey @eduard-cihunka

It's expected that you provided more information to PNK be able to parse and format phone numbers properly.

There are two ways to achieve this:

  1. Sending the complete number, which in this case would be +420777666555
  2. Sending the national number together with the region code, which is this case you would call the parse function like this: phoneNumberKit.parse("777666555", withRegion: "CZ")

Your issue though seems to be simple to fix, probably the property fullPhoneNumber of your model is a calculated property, so you can simply add a + at the beginning of the string and PNK will be able to do its job.

I hope it helps you.

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.