Link to home
Start Free TrialLog in
Avatar of ResourcefulDB
ResourcefulDB

asked on

email validation in python

hey, i have a little function in python to validate email. however aa@aa......com get pass. and aa@aa,com get pass too. how do we fix it.

thanks,
RDB.
def validateEmail(email_str):
        if (len(email_str)) > 6:
                if re.match("^[a-zA-Z0-9._%-]+@[a-zA-Z-9._%-]+.[a-zA-Z]{2,6}$",email_str) != None:
                        return 1
        return 0

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ResourcefulDB

ASKER

The example is C code that evaluates a character at a time and changes the context when a character of interest i.e. @ which is the separator of user and domain/hostname.

You could repeat the same process in python, but the regular expression achieves the same result.