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

`isValidPhoneNumber` returning true ignoring region #789

Open miguelgazela opened 1 month ago

miguelgazela commented 1 month ago

New Issue Checklist

Steps to reproduce

I'm trying to validate a phone number provided for a specific region, but if I give it with the country code behind it ignores the region I'm passing it and considers it valid.

let validPhoneNumber = phoneNumberKit?.isValidPhoneNumber("+351916693528", withRegion: "US")
Expected result

validPhoneNumber should be false

Actual result

validPhoneNumber is true

bguidolim commented 1 month ago

If you are using the international code, you shouldn't send the region. The parsing logic contains a couple of fallbacks to always try to bring the right result in the end, so if you send the international code AND the region, when the parsing for the region fails, it will fallback to the international code.

miguelgazela commented 1 month ago

Ok, so there's no way to enforce the region on the validation, right?

bguidolim commented 1 month ago

Right.

You can send the phone number without the international code.