#NEWLINE# def validate_email_address( emailaddress ) : #NEWLINE# #INDENT# '\n    Checks if an email address is syntactically correct.\n\n    Args:\n        emailaddress (str): Email address to validate.\n\n    Returns:\n        is_valid (bool): If this is a valid email or not.\n\n    Notes.\n        (This snippet was adapted from\n        http://commandline.org.uk/python/email-syntax-check.)\n\n    ' #NEWLINE# emailaddress = ( '%s' % emailaddress ) #NEWLINE# domains = ( 'aero' , 'asia' , 'biz' , 'cat' , 'com' , 'coop' , 'edu' , 'gov' , 'info' , 'int' , 'jobs' , 'mil' , 'mobi' , 'museum' , 'name' , 'net' , 'org' , 'pro' , 'tel' , 'travel' ) #NEWLINE# if ( len ( emailaddress ) < 7 ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( localpart , domainname ) = emailaddress . rsplit ( '@' , 1 ) #NEWLINE# ( host , toplevel ) = domainname . rsplit ( '.' , 1 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# if ( ( len ( toplevel ) != 2 ) and ( toplevel not in domains ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# for i in '-_.%+.' : #NEWLINE# #INDENT# localpart = localpart . replace ( host , '' ) #NEWLINE# #UNINDENT# for i in '-_.' : #NEWLINE# #INDENT# host = host . replace ( i , '' ) #NEWLINE# #UNINDENT# if ( localpart . isalnum ( ) and host . isalnum ( ) ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False