From 0082ee2bad9bf66cac204667d91b2d27e6604ddd Mon Sep 17 00:00:00 2001 From: David Kilias Date: Sun, 6 Dec 2020 21:54:36 +0100 Subject: [PATCH] =?UTF-8?q?validator=20bibliothek=20statt=20eigenen=20rege?= =?UTF-8?q?x=20f=C3=BCr=20email=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity_validator.py | 2 +- requirements.txt | 3 ++- validation_functions.py | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/entity_validator.py b/entity_validator.py index fbcd49e..6bbb497 100644 --- a/entity_validator.py +++ b/entity_validator.py @@ -66,7 +66,7 @@ def validate(entity): 'email': { 'type': 'string', 'required': True, - 'regex': '^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$'}, + 'check_with': valid_email}, 'fullname': { 'type': 'string', 'required': True}, diff --git a/requirements.txt b/requirements.txt index bfe4f57..04e43f1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ tornado==6.0.4 isodate==0.6.0 pytest==5.4.1 schwifty==2020.11.0 -Cerberus==1.3.2 \ No newline at end of file +Cerberus==1.3.2 +validator-collection==1.5.0 \ No newline at end of file diff --git a/validation_functions.py b/validation_functions.py index 45c0291..9e5b29a 100644 --- a/validation_functions.py +++ b/validation_functions.py @@ -1,5 +1,6 @@ from schwifty import IBAN, BIC import datetime +from validator_collection import validators, errors def valid_iban(field, value, error): try: @@ -28,4 +29,11 @@ def valid_money_amount(field, value, error): float(value) return True except (ValueError, TypeError): - error(field, 'not a valid money value') \ No newline at end of file + error(field, 'not a valid money value') + +def valid_email(field, value, error): + try: + validators.email(value) + return True + except errors.InvalidEmailError: + error(field, 'not a valid email') \ No newline at end of file