@@ -48,9 +48,12 @@ class ExtendedEmail(Email):
4848 1. spaces,
4949 2. special characters ,:;()<>[]\"
5050 3, multiple @ symbols,
51- 4, leading, trailing, or consecutive dots in the local part
52- 5, invalid domain part - missing top level domain (user@example), consecutive dots
53- Custom check for additional invalid characters disallows |'— because they make our email sending service to fail
51+ 4, leading, trailing, or consecutive dots in the local part,
52+ 5, invalid domain part - missing top level domain (user@example), consecutive dots,
53+ Custom check for
54+ - additional invalid characters disallows |'—
55+ - non-ASCII characters in the domain part
56+ because they make our email sending service to fail
5457 """
5558
5659 def __call__ (self , form , field ):
@@ -61,6 +64,17 @@ def __call__(self, form, field):
6164 f"Email address '{ field .data } ' contains an invalid character."
6265 )
6366
67+ try :
68+ local_part , domain_part = field .data .rsplit ("@" , 1 )
69+ except ValueError :
70+ raise ValidationError (f"Invalid email address '{ field .data } '." )
71+
72+ # character is one of the standard ASCII characters (0–127)
73+ if not all (ord (c ) < 128 for c in domain_part ):
74+ raise ValidationError (
75+ f"Email address '{ field .data } ' contains non-ASCII characters in the domain part."
76+ )
77+
6478
6579class PasswordValidator :
6680 def __init__ (self , min_length = 8 ):
0 commit comments