472,374 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

Email Validation with domain

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
Jul 2 '08 #1
4 4743
oj
On Jul 2, 12:41*pm, Sallu <praveen.sunsetpo...@gmail.comwrote:
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.
Jul 2 '08 #2
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....d7d31bebc09190
# * 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-0...lHostnameCheck
Jul 2 '08 #3
Sallu <pr*****************@gmail.comwrites:
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
Jul 2 '08 #4
On Jul 2, 6:25*pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
Sallu <praveen.sunsetpo...@gmail.comwrites:
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..
Jul 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JDJones | last post by:
I have a script that uses the following eregi to check for a valid email address: if (!eregi("^+@(+\.)+{2,4}$", $email)) { print_error("your <b>email address</b> is invalid"); } While this...
9
by: news | last post by:
There's all kinds of ways to validate an email address to make sure it's well formed and whatnot, but what about checking to see if it's a valid e-mail account? Like how you can use checkdnsrr()...
10
by: Chris Sharman | last post by:
I'm doing a rough validation of an email address client-side (using js), but it's not enough - our customer service people are apparently incapable of typing in an email address without error - we...
12
by: Dag Sunde | last post by:
My understanding of regular expressions is rudimentary, at best. I have this RegExp to to a very simple validation of an email-address, but it turns out that it refuses to accept mail-addresses...
2
by: martin | last post by:
Hi, I would like to validate an email address from .net. Now before you scream regular expression I would like something a bit better than this. I would like to validate the domain, and maybe...
3
by: Shapper | last post by:
Hello, I have an aspx.vb code with a function. In this function I need to check if a variable is a valid email address. Something like: address@domain.extension How can I do this? Thanks,
23
by: codefire | last post by:
Hi, I am trying to get a regexp to validate email addresses but can't get it quite right. The problem is I can't quite find the regexp to deal with ignoring the case james..kirk@fred.com, which...
10
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.