473,413 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Validating an email address

Hi all,

A hoary old chestnut this - any advice on how to syntactically validate an
email address? I'd like to support both the display-name-and-angle-bracket
and bare-address forms, and to allow everything that RFC 2822 allows (and
nothing more!).

Currently, i've got some regexps which recognise a common subset of
possible addresses, but it would be nice to do this properly - i don't
currently support quoted pairs, quoted strings, or whitespace in various
places where it's allowed. Adding support for those things using regexps
is really hard. See:

http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html

For a level to which i am not prepared to stoop.

I hear the email-sig are open to adding a validation function to the email
package, if a satisfactory one can be written; i would definitely support
their doing that.

tom

--
Women are monsters, men are clueless, everyone fights and no-one ever
wins. -- cleanskies
Dec 9 '05 #1
3 2378
Tom Anderson <tw**@urchin.earth.li> wrote:
A hoary old chestnut this - any advice on how to syntactically
validate an email address?


Yes: Don't.

<URL:http://www.apps.ietf.org/rfc/rfc3696.html#sec-3>

The only validation you should be doing before sending the message is
on the domain part. Since there are records available in DNS to
verify, you can check those. Is there an MX record? Is the address
valid? Do the mappings both way for that record make sense?

Please, don't attempt to "validate" the local-part. It's not up to you
to decide what the receiving MTA will accept as a local-part, and
(short of asking the MTA which most of them disable due to abuse by
spammers) you can't find out without just delivering the message.

So, once you've determined that you can reach the MX host, and that it
actually *is* the MX host for the domain, just deliver the message.

--
\ "Those who can make you believe absurdities can make you commit |
`\ atrocities." -- Voltaire |
_o__) |
Ben Finney
Dec 9 '05 #2
On Sat, 10 Dec 2005, Ben Finney wrote:
Tom Anderson <tw**@urchin.earth.li> wrote:
A hoary old chestnut this - any advice on how to syntactically
validate an email address?
Yes: Don't.

<URL:http://www.apps.ietf.org/rfc/rfc3696.html#sec-3>


The IETF must have updated that RFC between you posting the link and me
reading it, because that's not what it says. What it says that the syntax
for local parts is complicated, and many of the variations are actually
used for reasons i can't even imagine, so they should be permitted. It
doesn't say anything about not validating the local part against that
syntax.
Please, don't attempt to "validate" the local-part. It's not up to you
to decide what the receiving MTA will accept as a local-part,


Absolutely not - it's up to the IETF, and their decision is recorded in
RFC 2822.

tom

--
Whose house? Run's house!
Dec 10 '05 #3
Tom Anderson <tw**@urchin.earth.li> writes:
On Sat, 10 Dec 2005, Ben Finney wrote:
Please, don't attempt to "validate" the local-part. It's not up to
you to decide what the receiving MTA will accept as a local-part,

Absolutely not - it's up to the IETF, and their decision is recorded
in RFC 2822.


Wrong. The IETF dictates what your MTA *must* accept, not what it will
accept. It's perfectly legal to accept more than what the IETF says is
legal. In fact the rule of thumb for interoperability (on the off
chance that anyone still cares about such) is "be generous in what you
accept, and strict in what you send", so you're even encouraged to
accept more than what the IETF says you have to.

If you didn't generate the address, you have no way of knowing if the
the receiving MTA will accept it or not without actually trying
it. Rejecting an address because you don't like it could break
perfectly functional email addresses.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Dec 10 '05 #4

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

Similar topics

3
by: Mark | last post by:
Hi, Im trying to validate a form, all the validating works apart from one field. This particular field must consist of the first 2 characters as letters, & the following 5 as numbers. And if it...
17
by: Sue | last post by:
<html> Is there someone here that can help me validate the period as the fourth from the last character in an email address. There is other information and validation on the form I have to do but...
3
by: Guju | last post by:
Hi all, I am a newbie to sql and I need your help. I want to update column (email) from one table to another validating the Customerid column in both table. Update the email address in...
15
by: qazmlp | last post by:
What is the best & fastest way of validating an IPv4 address? Basically, the input can be either in IPAddressv4 or IPAddressv4:port format. Currently I have the following code to validate the...
1
by: Henrik Nyberg | last post by:
Here's a small method for validating email in C#. It may save you some time.. public static bool IsValidEmailAddress(string sEmail) { if (sEmail == null) { return false; } int nFirstAT =...
2
by: Doug | last post by:
I'm a little confused by this functionality. It doesn't seem to be behaving like it should. I am using the following regular expression to validate email addresses:...
6
by: yochessyo | last post by:
Hi, I would like to validate email addresses. I am not interested to validate it with a regex expression but from the email server where the addresses are. I would like to query this server and...
1
by: zaidalin79 | last post by:
I am in a JavaScript class, and we have to get all of our code to validate at the w3c website... Here is my code, it does what I want it to do which is require the user to enter the name and either...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.