|
From: Sallu on 2 Jul 2008 07:41 Hi All, import re msg=raw_input('Enter the email : ') def validateEmail(email): #if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9] {1,3})(\\]?)$", email) != None: if re.match("^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$", email) != None: print 'Valis' else: print 'not' validateEmail(msg) i wrote a script above it works fine but it does not check for valid domain like .com .org .in how to validate with domain
From: oj on 2 Jul 2008 08:33 On Jul 2, 12:41 pm, Sallu <praveen.sunsetpo...(a)gmail.com> wrote: > Hi All, import re > msg=raw_input('Enter the email : ') > > def validateEmail(email): > > #if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9] > {1,3})(\\]?)$", email) != None: > if re.match("^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$", > email) != None: > print 'Valis' > else: > print 'not' > > validateEmail(msg) i wrote a script above it works fine but it does > not check for valid domain like .com .org .in > how to validate with domain Don't try and check that the TLD (.com .org etc.) is valid with a regular expression. Just don't. Especially now that the rules about domain names are now being relaxed and there is no possible way of you predicating what all the new TLDs will be. Validating that that the e-mail address is in a valid form, and validating the domain is valid are two separate things. If you want to validate the domain, do a DNS lookup on the domain or some such. I don't think there are standard modules to provide this functionality included with python. You could try using the socket module, and reading up on the relevant protocols, or making calls to external programs.
From: livibetter on 2 Jul 2008 08:52 > If you want to validate the domain, do a DNS lookup on the domain or > some such. I don't think there are standard modules to provide this > functionality included with python. You could try using the socket > module, and reading up on the relevant protocols, or making calls to > external programs. I agreed. I made quick code for this. # Email address validator # # This module is in Public Domain # # This module was written for replying to # http://groups.google.com/group/comp.lang.python/browse_thread/thread/80d7d31bebc09190 # * It requires dnspython (http://www.dnspython.org/). # * It is a simple prototype. # * It would be slow if query mass email addresses, having cache mechanism # would be very helpful. # * It only checks hostname of email address. # # Author : Yu-Jie Lin # Creation Date: 2008-07-02T20:09:07+0800 import dns.resolver def CheckEmail(email): """This function directly extracts the hostname and query it""" email_parts = email.split('@') if len(email_parts) != 2: return False # Start querying try: answers = dns.resolver.query(email_parts[1], 'MX') except dns.resolver.NoAnswer: # This host doesn't have MX records return False except dns.resolver.NXDOMAIN: # No such hostname return False # Possible a valid hostname return True I also wrote a short blog post for this post and the code, if you are interested, you can read it at http://thetinybit.com/Blog/2008-07-02-2047-EmailHostnameCheck
From: Ben Finney on 2 Jul 2008 09:25 Sallu <praveen.sunsetpoint(a)gmail.com> writes: > validateEmail(msg) i wrote a script above it works fine Actually, no. It rejects a great many email addresses that are valid. > but it does not check for valid domain like .com .org .in how to > validate with domain To validate a domain for delivery of email, check with the DNS by requesting the A or MX record for that domain. To validate an email address, check with the mail server for that domain by sending a message to the address. Neither of them should be "validated" by a regular expression. Please refer to RFC 3696 <URL:http://www.ietf.org/rfc/rfc3696.txt> described as "Recommended techniques for applications checking or manipulating domain and other internet names". -- \ “Pinky, are you pondering what I'm pondering?” “Wuh, I think | `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | _o__) overnight?” —_Pinky and The Brain_ | Ben Finney
From: Sallu on 3 Jul 2008 01:38 On Jul 2, 6:25 pm, Ben Finney <bignose+hates-s...(a)benfinney.id.au> wrote: > Sallu <praveen.sunsetpo...(a)gmail.com> writes: > > validateEmail(msg) i wrote a script above it works fine > > Actually, no. It rejects a great many email addresses that are valid. > > > but it does not check for valid domain like .com .org .in how to > > validate with domain > > To validate a domain for delivery of email, check with the DNS by > requesting the A or MX record for that domain. > > To validate an email address, check with the mail server for that > domain by sending a message to the address. > > Neither of them should be "validated" by a regular expression. > > Please refer to RFC 3696 <URL:http://www.ietf.org/rfc/rfc3696.txt> > described as "Recommended techniques for applications checking or > manipulating domain and other internet names". > > -- > \ Pinky, are you pondering what I'm pondering? Wuh, I think | > `\ so, Brain, but wouldn't anything lose its flavor on the bedpost | > _o__) overnight? _Pinky and The Brain_ | > Ben Finney Thank you to all of you and clearing my idea..
|
Pages: 1 Prev: Scripting SAP GUI (Windows) Next: How to modify the data in a binary file? |