Skip to content
New issue

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

add support for all country codes #17

Closed
wants to merge 1 commit into from
Closed

Conversation

sanduluca
Copy link

@sanduluca sanduluca commented Jul 14, 2023

I've added support for all country codes using the lib methods.
Solves #5
Closes #16

This should be a major release, because the api changed.

I've also created a PR (May 10, 2023) to the original yup-phone library, but it seems to be unmaintained.
abhisekp/yup-phone#823

Please take a look to this PR. Any feedback is welcome.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6fdc4b9:

Sandbox Source
yup-phone-lite vanilla Configuration
yup-phone-lite typescript Configuration

@csandman
Copy link
Owner

Sorry for the late reply, but this PR doesn't really do what you describe it as. The function you used for your non-strict mode phoneNumber.isValid() is the same as the one this package uses by default; isValidPhoneNumber(). I see you used isValidNumberForRegion, but that option just makes the requirements more strict, it is not the same as this package's default.

If you look at the isValidNumberForRegion docs in libphonenumber-js.

The optional defaultCountry argument is the default country, i.e. it does not restrict to just that country, e.g. in those cases where several countries share the same phone numbering rules (NANPA, Britain, etc). For example, even though the number 07624 369230 belongs to the Isle of Man ("IM" country code) calling isValidNumber('07624369230', 'GB') still returns true because the country is not restricted to GB, it's just that GB is the default one for the phone numbering rules. For restricting the country, see isValidNumberForRegion(), though restricting a country might not be a good idea.

You can see that it's only difference is restricting the region, where as by default any numbers sharing the same phone numbering rules will return as valid, which this package already does. If you try one of the CodeSandbox examples generated above, you can see, if you enter a Russian number or something like that in the input, the validation will still fail in "non-strict" mode.


As a side note, deleting a bunch of tests isn't a great way to have a PR approved.

@csandman csandman closed this Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How do I accept all country codes?
2 participants