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

PythonLinux

Avatar of undefined
Last Comment
arnold
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of pepr
pepr

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of ResourcefulDB
ResourcefulDB

ASKER

Avatar of arnold
arnold
Flag of United States of America image

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.
Linux
Linux

Linux is a UNIX-like open source operating system with hundreds of distinct distributions, including: Fedora, openSUSE, Ubuntu, Debian, Slackware, Gentoo, CentOS, and Arch Linux. Linux is generally associated with web and database servers, but has become popular in many niche industries and applications.

71K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo