Karagan App Karagan App - 3 months ago 10
Swift Question

How would you match two similar phone numbers in Swift, but one contains the country code and the other one does or does not

I am trying to match to match two similar phone numbers in swift, but one of them is preceded by a country code and the other one can vary. For instance, I want these 2 phone numbers to match:

0499999999

+32499999999

Of course I want this to be valid for any phone number all over the world. Is there a regex for this or maybe a pod I could download for doing this?

Thanks

Answer

I don't think there will be a way until unless you store the phone number apart from the country code or local code or 0 because you dont know how many digits could there be as country code or local code also not all countries use 10 or 11 digits phone number system so the idea of trimming the number forwards or backwards and then try to match is also moot.

PS:- That is a reason why most apps you see have a different field for country code, they just display it with the number , but in the back are storing it separately. As for cocoapods just search its site with keyword phonenumber