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

Phone number validation should take region into account #351

Open
JulienPalard opened this issue Sep 13, 2024 · 0 comments
Open

Phone number validation should take region into account #351

JulienPalard opened this issue Sep 13, 2024 · 0 comments

Comments

@JulienPalard
Copy link
Contributor

Currently the validation of phone number is left to the model fields, but the AbstractShippingAddress model can't really do phone validation alone, the only thing it can do is to use the PHONENUMBER_DEFAULT_REGION settings, which is not enough.

Oscar side, with good old forms, they use a PhoneNumberMixin which does the validation like (simplified):

        try:
            phone_number = PhoneNumber.from_string(number)
        except phonenumbers.NumberParseException:
            try:
                phone_number = PhoneNumber.from_string(number, region=self.region_code)
                if not phone_number.is_valid():
                    ...

Maybe UserAddressSerializer could have its own phone number validation, making use of the user provided country to give a proper region to the phonenumber_field library?

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

No branches or pull requests

1 participant