From 8a77a87ad9289905c872d7f6f07472e0fb30de82 Mon Sep 17 00:00:00 2001 From: Ankur Agarwal Date: Sun, 16 Aug 2015 23:30:42 +0530 Subject: [PATCH] Added extra check for invalid input string --- cleansweep/forms.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cleansweep/forms.py b/cleansweep/forms.py index 27f1d37..c6ec857 100644 --- a/cleansweep/forms.py +++ b/cleansweep/forms.py @@ -71,7 +71,13 @@ def validate_phone(self, field): raise validators.ValidationError('it should be 10 digit only') phone = field.data.strip() - if phonenumbers.is_valid_number(phonenumbers.parse(phone, "IN")) == False: + + try: + number = phonenumbers.parse(phone, "IN") + except Exception: + raise validators.ValidationError('Please enter number only') + + if phonenumbers.is_valid_number(number) == False: raise validators.ValidationError('Invalid Phone number') if models.Member.find(phone=phone):