Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

  • Advertisements

Email Validation With Valid Domain

Posted by Praveen Kumar on July 3, 2008

GENERIC_DOMAINS = “aero”, “asia”, “biz”, “cat”, “com”, “coop”, \
“edu”, “gov”, “info”, “int”, “jobs”, “mil”, “mobi”, “museum”, \
“name”, “net”, “org”, “pro”, “tel”, “travel”

def valid1(emailaddress, domains = GENERIC_DOMAINS):
“””Checks for a syntactically invalid email address.”””

# Email address must be 7 characters in total.
if len(emailaddress) < 7:
#return True # Address too short.
print “Address too short”
# Split up email address into parts.
localpart, domainname = emailaddress.rsplit(‘@’, 1)
host, toplevel = domainname.rsplit(‘.’, 1)
except ValueError:
#return True # Address does not have enough parts.
print “Address does not have enough parts.”

# Check for Country code or Generic Domain.
if len(toplevel) != 2 and toplevel not in domains:
#return True # Not a domain name.
print “Not a domain name”
return True
for i in ‘-_.%+.’:
localpart = localpart.replace(i, “”)
for i in ‘-_.’:
host = host.replace(i, “”)

if localpart.isalnum() and host.isalnum():
#return False # Email address is fine.
print “valid”
#return True # Email address has funny characters.
print “InValid”

msg=raw_input(‘Enter the email : ‘)

Without Domain simple script

import re
msg=raw_input(‘Enter the email : ‘)

def validateEmail(email):

if re.match(“^([^@.$%^&*#\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$”, email) == None:
print ‘Not Valid’
print ‘Valid’



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: