Validate International phone numbers

- uses new utils methods to validate phone numbers
- defaults to International=True on validation. This ensures the validator works on all numbers
- Then check if the user can send this message to the number internationally if needed.
This commit is contained in:
Martyn Inglis
2017-04-26 15:56:45 +01:00
parent 3d312c7342
commit 2a0f8c8808
12 changed files with 224 additions and 28 deletions
+2 -2
View File
@@ -324,13 +324,13 @@ class SmsNotificationSchema(NotificationSchema):
@validates('to')
def validate_to(self, value):
try:
validate_phone_number(value)
validate_phone_number(value, international=True)
except InvalidPhoneError as error:
raise ValidationError('Invalid phone number: {}'.format(error))
@post_load
def format_phone_number(self, item):
item['to'] = validate_and_format_phone_number(item['to'])
item['to'] = validate_and_format_phone_number(item['to'], international=True)
return item