From aeeef8601206314c4cdc6aa25a16e561174c80ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 24 Jun 2017 11:03:09 +0200 Subject: [PATCH] Validate phone numbers In addition to parsing the number, we can also validate it with the phonenumbers library. issue6567 review42411002 --- contact_mechanism.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contact_mechanism.py b/contact_mechanism.py index ffa03794c0..880e4edde1 100644 --- a/contact_mechanism.py +++ b/contact_mechanism.py @@ -259,8 +259,10 @@ class ContactMechanism(sequence_ordered(), ModelSQL, ModelView): if not phonenumbers or self.type not in _PHONE_TYPES: return try: - phonenumbers.parse(self.value) + phonenumber = phonenumbers.parse(self.value) except NumberParseException: + phonenumber = None + if not (phonenumber and phonenumbers.is_valid_number(phonenumber)): self.raise_user_error( 'invalid_phonenumber', { 'phone': self.value,