April 6, 2017

How to validate an email address using Python Script?

Code snippet to validate the email id taken as an input via command line

# Python script to validate input email address
# for system input
import sys
print(sys.argv)

# for regular expression
import re
print "\n" 

email_id = raw_input("Please enter your email id: ")
if re.match("[^@]+@[^@]+\.[^@]+", email_id):
print "Hurray! you have entered a valid email id: ", email_id
else:
print "Better luck next time with a valid email id"

No comments:

Post a Comment