Use phonenumbers package to validate live settings twilio number instead of regex to support EU number

This commit is contained in:
Michael Derynck 2022-09-21 12:22:05 -06:00
parent 3db4038a4f
commit edac2e334f

View file

@ -2,6 +2,7 @@ import json
import re
from urllib.parse import urlparse
import phonenumbers
from django.apps import apps
from python_http_client import UnauthorizedError
from sendgrid import SendGridAPIClient
@ -125,7 +126,8 @@ class LiveSettingValidator:
@staticmethod
def _is_phone_number_valid(phone_number):
return re.match(r"^\+\d{11}$", phone_number)
ph_num = phonenumbers.parse(phone_number)
return phonenumbers.is_valid_number(ph_num)
@staticmethod
def _prettify_twilio_error(exc):