Skip to content

Commit

Permalink
Merge pull request #90 from devilankur18/phone_number_validation
Browse files Browse the repository at this point in the history
Extra validation for invalid input
  • Loading branch information
anandology committed Aug 16, 2015
2 parents cd99467 + 8a77a87 commit a73caf4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cleansweep/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a73caf4

Please sign in to comment.