Skip to content

Phone number validation should take region into account #351

@JulienPalard

Description

@JulienPalard

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions