- email = email.lower()
- at_sign = email.find('@')
- if at_sign < 1:
- raise invalid_email
- user = email[:at_sign]
- rest = email[at_sign+1:]
- domain = rest.split('.')
-
- # This means local, unqualified addresses, are not allowed
- if not domain:
- raise invalid_email
- if len(domain) < 2:
+ email_re = re.compile('\A[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9._\-]+\.[a-zA-Z]+\Z')
+ if not email_re.match(email):