-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle regions sharing country code in PhoneNumberPrefixWidget
Each choice should be indexed with a unique value, use the region ISO code over the national prefix. Fixes #133 Fixes #251 Fixes #489
- Loading branch information
1 parent
4435e86
commit 882cee6
Showing
3 changed files
with
203 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from phonenumber_field.phonenumber import to_python | ||
from phonenumber_field.phonenumber import PhoneNumber, to_python | ||
|
||
|
||
def validate_international_phonenumber(value): | ||
phone_number = to_python(value) | ||
if phone_number and not phone_number.is_valid(): | ||
if isinstance(phone_number, PhoneNumber) and not phone_number.is_valid(): | ||
raise ValidationError( | ||
_("The phone number entered is not valid."), code="invalid_phone_number" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters