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?
Currently the validation of phone number is left to the model fields, but the
AbstractShippingAddressmodel can't really do phone validation alone, the only thing it can do is to use thePHONENUMBER_DEFAULT_REGIONsettings, which is not enough.Oscar side, with good old forms, they use a
PhoneNumberMixinwhich does the validation like (simplified):Maybe
UserAddressSerializercould have its own phone number validation, making use of the user provided country to give a proper region to thephonenumber_fieldlibrary?