You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _
from phonenumber_field.phonenumber import to_python
def get_validator_class():
if getattr(settings, 'TWO_FACTOR_PHONENUMBER_VALIDATOR', None):
return import_string(settings.TWO_FACTOR_PHONENUMBER_VALIDATOR)
return validate_international_phonenumber
def validate_international_phonenumber(value):
phone_number = to_python(value)
if phone_number and not phone_number.is_valid():
raise ValidationError(validate_international_phonenumber.message,
code='invalid')
validate_international_phonenumber.message =
_('Please enter a valid phone number, including your country code '
'starting with + or 00.')
This way I can check for the likes of country codes etc on the phone number.
Just wanted to let you know incase this is something you have not thought of or it may be that I have not found a way to do it.
Once again thanks for this, a great repo :)
Stuart
The text was updated successfully, but these errors were encountered:
Hi Stuart. First of all, thank you! Can you elaborate on why you need additional validators, besides the newly added validation of the phonenumbers library? Maybe I'll make validating phone numbers a responsibility of the gateway, so you can customize the validation over there.
Hey Bouke,
Just want to say love this project and am currently using it on two of my sites. Fantastic work :)
Just a thought for you, what I have had to do for both projects is folk the project so I can override you validator to use my own, am still fairly new to python so know of no other way to get round this so feel free to advise.
https://github.com/bigmassa/django-two-factor-auth/commit/52f542604a1619ea6d831de71829db38bfeb5841
What ive done is following:
from django.conf import settings
from django.core.exceptions import ValidationError
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _
from phonenumber_field.phonenumber import to_python
def get_validator_class():
if getattr(settings, 'TWO_FACTOR_PHONENUMBER_VALIDATOR', None):
return import_string(settings.TWO_FACTOR_PHONENUMBER_VALIDATOR)
return validate_international_phonenumber
def validate_international_phonenumber(value):
phone_number = to_python(value)
if phone_number and not phone_number.is_valid():
raise ValidationError(validate_international_phonenumber.message,
code='invalid')
validate_international_phonenumber.message =
_('Please enter a valid phone number, including your country code '
'starting with + or 00.')
This way I can check for the likes of country codes etc on the phone number.
Just wanted to let you know incase this is something you have not thought of or it may be that I have not found a way to do it.
Once again thanks for this, a great repo :)
Stuart
The text was updated successfully, but these errors were encountered: