Programming in almost language

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

Archive for the ‘Python Code’ Category

Regular Expression Booster

Posted by Pratap on April 29, 2009

Hi this for those who are new to regular expression and python programming
If you want to understand it through python code then download kodos this tool is ultimate booster for newbies..
Cheers!!

Posted in Python Code | Tagged: | 1 Comment »

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.
try:
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”
else:
#return True # Email address has funny characters.
print “InValid”

msg=raw_input(‘Enter the email : ‘)
valid1(msg)

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’
else:
print ‘Valid’

validateEmail(msg)

Posted in Python Code | Leave a Comment »