Connecting Tech Pros Worldwide Forums | Help | Site Map

best email validator

Fred
Guest
 
Posts: n/a
#1: Aug 25 '08
I'm researching and I see various approaches, with or without regex. So I'm
asking for opinions on which is the best - that is, the most thorough. Thanks.

Thiago Macedo
Guest
 
Posts: n/a
#2: Aug 25 '08

re: best email validator


On Aug 25, 1:46 pm, Fred <F...@notspam.notwrote:
Quote:
I'm researching and I see various approaches, with or without regex. So I'm
asking for opinions on which is the best - that is, the most thorough. Thanks.
Unless your have AJAX as an option, I found REGEX to be the best
solution.
Ajax could be bether when you need to check if the domain and account
is valid on the mailserver.

Thiago
Dr J R Stockton
Guest
 
Posts: n/a
#3: Aug 25 '08

re: best email validator


In comp.lang.javascript message <g8unlf$u30$1@aioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <Fred@notspam.notposted:
Quote:
>I'm researching and I see various approaches, with or without regex. So I'm
>asking for opinions on which is the best - that is, the most thorough. Thanks.
Setting that is a useful way for a teacher to tell whether a student is
intelligent or clever or knowledgeable on the course material.

But since there is no way for JavaScript string routines to tell whether
or not Fred <Fred@notspam.com is or will be a deliverable E-mail
address, the exercise has no practical use.

<URL:http://www.merlyn.demon.co.uk/js-balid.htmrefers.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Laser Lips
Guest
 
Posts: n/a
#4: Aug 26 '08

re: best email validator


On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Quote:
In comp.lang.javascript message <g8unlf$u3...@aioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.notposted:
>
Quote:
I'm researching and I see various approaches, with or without regex. So I'm
asking for opinions on which is the best - that is, the most thorough. Thanks.
>
Setting that is a useful way for a teacher to tell whether a student is
intelligent or clever or knowledgeable on the course material.
>
But since there is no way for JavaScript string routines to tell whether
or not Fred <F...@notspam.com is or will be a deliverable E-mail
address, the exercise has no practical use.
>
<URL:http://www.merlyn.demon.co.uk/js-balid.htmrefers.
>
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
>
--
(c) John Stockton, nr London UK. ?...@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
function emailCheck(e)
{
var emailStr;
emailStr = e;
valid = true;

var checkTLD=0;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|
coop|info|pro|museum|uk|se)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null)
{
//alert("The email address is invalid");
valid = false;
}else
{
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++)
{
if (user.charCodeAt(i)>127)
{
//alert("The username contains invalid Characters.");
valid = false;
}
}
for (i=0; i<domain.length; i++)
{
if (domain.charCodeAt(i)>127)
{
//alert("The domain dame contains invalid characters.");
valid = false;
}
}
if (user.match(userPat)==null)
{
//alert("The username is invalid.");
valid = false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null)
{
for (var i=1;i<=4;i++)
{
if (IPArray[i]>255)
{
//alert("The destination IP address is invalid.");
valid = false;
}
}

}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++)
{
if (domArr[i].search(atomPat)==-1)
{
//alert("The domain name is invalid.");
valid = false;
}
}
if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1)
{
//alert("The domain name extension is invalid");
valid = false;
}
if (len<2)
{
//alert("The address is missing a hostname.");
valid = false;
}
}
return valid;
}
Laser Lips
Guest
 
Posts: n/a
#5: Aug 26 '08

re: best email validator


On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Quote:
In comp.lang.javascript message <g8unlf$u3...@aioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.notposted:
>
Quote:
I'm researching and I see various approaches, with or without regex. So I'm
asking for opinions on which is the best - that is, the most thorough. Thanks.
>
Setting that is a useful way for a teacher to tell whether a student is
intelligent or clever or knowledgeable on the course material.
>
But since there is no way for JavaScript string routines to tell whether
or not Fred <F...@notspam.com is or will be a deliverable E-mail
address, the exercise has no practical use.
>
<URL:http://www.merlyn.demon.co.uk/js-balid.htmrefers.
>
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
>
--
(c) John Stockton, nr London UK. ?...@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Or, you could use PHP and do an AJEX call to the PHP script to check
the Email address.
Laser Lips
Guest
 
Posts: n/a
#6: Aug 26 '08

re: best email validator


On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.demon.co.ukwrote:
Quote:
In comp.lang.javascript message <g8unlf$u3...@aioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.notposted:
>
Quote:
I'm researching and I see various approaches, with or without regex. So I'm
asking for opinions on which is the best - that is, the most thorough. Thanks.
>
Setting that is a useful way for a teacher to tell whether a student is
intelligent or clever or knowledgeable on the course material.
>
But since there is no way for JavaScript string routines to tell whether
or not Fred <F...@notspam.com is or will be a deliverable E-mail
address, the exercise has no practical use.
>
<URL:http://www.merlyn.demon.co.uk/js-balid.htmrefers.
>
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
>
--
(c) John Stockton, nr London UK. ?...@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
AJAX not AJEX
Bart Van der Donck
Guest
 
Posts: n/a
#7: Aug 26 '08

re: best email validator


Laser Lips wrote:
Quote:
function emailCheck(e)
{
* * * * var emailStr;
* * * * emailStr = e;
* * * * valid = true;
>
* * * * var checkTLD=0;
* * * * var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|
coop|info|pro|museum|uk|se)$/;
* * * * var emailPat=/^(.+)@(.+)$/;
* * * * var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
* * * * var validChars="\[^\\s" + specialChars + "\]";
* * * * var quotedUser="(\"[^\"]*\")";
* * * * var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
* * * * var atom=validChars + '+';
* * * * var word="(" + atom + "|" + quotedUser + ")";
* * * * var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
* * * * var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
* * * * var matchArray=emailStr.match(emailPat);
>
* * * * if (matchArray==null)
* * * * {
* * * * * * * * //alert("The email address is invalid");
* * * * * * * * valid = false;
* * * * }else
* * * * {
* * * * * * * * var user=matchArray[1];
* * * * * * * * var domain=matchArray[2];
>
* * * * * * * * for (i=0; i<user.length; i++)
* * * * * * * * {
* * * * * * * * * * * * if (user.charCodeAt(i)>127)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * //alert("The username contains invalid Characters.");
* * * * * * * * * * * * * * * * valid =false;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * for (i=0; i<domain.length; i++)
* * * * * * * * {
* * * * * * * * * * * * if (domain.charCodeAt(i)>127)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * //alert("The domain dame contains invalid characters.");
* * * * * * * * * * * * * * * * valid =false;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * if (user.match(userPat)==null)
* * * * * * * * {
* * * * * * * * * * * * //alert("The username is invalid.");
* * * * * * * * * * * * valid = false;
* * * * * * * * }
>
* * * * * * * * var IPArray=domain.match(ipDomainPat);
* * * * * * * * if (IPArray!=null)
* * * * * * * * {
* * * * * * * * * * * * for (var i=1;i<=4;i++)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * if (IPArray[i]>255)
* * * * * * * * * * * * * * * * {
* * * * * * * * * * * * * * * * * * * * //alert("The destination IP address is invalid.");
* * * * * * * * * * * * * * * * * * * * valid = false;
* * * * * * * * * * * * * * * * }
* * * * * * * * * * * * }
>
* * * * * * * * }
* * * * * * * * var atomPat=new RegExp("^" + atom + "$");
* * * * * * * * var domArr=domain.split(".");
* * * * * * * * var len=domArr.length;
* * * * * * * * for (i=0;i<len;i++)
* * * * * * * * {
* * * * * * * * * * * * if (domArr[i].search(atomPat)==-1)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * //alert("The domain name is invalid.");
* * * * * * * * * * * * * * * * valid =false;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * if (checkTLD && domArr[domArr.length-1].length!=2 &&
domArr[domArr.length-1].search(knownDomsPat)==-1)
* * * * * * * * {
* * * * * * * * * * * * //alert("The domain name extension is invalid");
* * * * * * * * * * * * valid = false;
* * * * * * * * }
* * * * * * * * if (len<2)
* * * * * * * * {
* * * * * * * * * * * * //alert("The address is missing a hostname.");
* * * * * * * * * * * * valid = false;
* * * * * * * * }
* * * * }
* * * * return valid;
>
}
Nice code.

I would not allow aa/bb@test.com, because slash is often used as
directory separator to store mail.

aa@test.a is maybe RFC2822-compliant, but TLD's should consist of at
least 2 characters (I suppose you're not interested in filtering on
valid LAN-hostnames).

a@#b.com, a@b{c.com, a@$b.com, a@b.com' etc. are wrong; those signs
are not allowed in domain names.

The condition " if (myvar.charCodeAt(i)>127) { ... " is probably too
broad; lots of <127 characters are not allowed too.

Your variable 'knownDomsPat' creates confusion; the script doesn't
appear to check further on it (I wouldn't use such a lookup-array
anyhow).

A readable summary of RFC 2822:
http://en.wikipedia.org/wiki/E-mail_..._Specification

All a bit academic though. Note that Windows Hotmail only allows
alphanumerics, dot (.), underscore (_) and hyphen (-) for the full
address. In practice I would probably use such a "real-world"
criterion as well.

Hope this helps,

--
Bart
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#8: Aug 26 '08

re: best email validator


Bart Van der Donck wrote:
Quote:
Laser Lips wrote:
Quote:
>function emailCheck(e) {
> [...]
>}
>
Nice code.
For fitting values of "nice".
Quote:
I would not allow aa/bb@test.com, because slash is often used as
directory separator to store mail.
That is a non sequitur to me.
Quote:
[...]
Another issue is that foo@[x.y.z.255] certainly does not specify a mailbox.
IPv6 addresses are also not supported although that would be standard
compliant. And that is likely not the end of it.
Quote:
[...] Note that Windows Hotmail only allows alphanumerics, dot (.),
underscore (_) and hyphen (-) for the full address.
That is good to know, thanks.
Quote:
In practice I would probably use such a "real-world" criterion as well.
As for that, I had already derived a regular expression from the addr-spec
specification of RFC2822, and posted it here a while ago, IIRC without much
debate afterwards.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Laser Lips
Guest
 
Posts: n/a
#9: Aug 26 '08

re: best email validator


On Aug 26, 1:06 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
Bart Van der Donck wrote:
>
Quote:
Laser Lips wrote:
Quote:
function emailCheck(e) {
[...]
}
>
Quote:
Nice code.
>
For fitting values of "nice".
>
Quote:
I would not allow aa...@test.com, because slash is often used as
directory separator to store mail.
>
That is a non sequitur to me.
>
Quote:
[...]
>
Another issue is that foo@[x.y.z.255] certainly does not specify a mailbox.
IPv6 addresses are also not supported although that would be standard
compliant. And that is likely not the end of it.
>
Quote:
[...] Note that Windows Hotmail only allows alphanumerics, dot (.),
underscore (_) and hyphen (-) for the full address.
>
That is good to know, thanks.
>
Quote:
In practice I would probably use such a "real-world" criterion as well.
>
As for that, I had already derived a regular expression from the addr-spec
specification of RFC2822, and posted it here a while ago, IIRC without much
debate afterwards.
>
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Sorry, was being lazy, I did'nt write that code, used it ages ago and
seems to do the job. Just thought it would for Freds purpose.
Dr J R Stockton
Guest
 
Posts: n/a
#10: Aug 26 '08

re: best email validator


In comp.lang.javascript message <cf5469cd-9131-4c85-b83f-53effaa0bad6@m4
4g2000hsc.googlegroups.com>, Mon, 25 Aug 2008 10:32:18, Thiago Macedo
<thiago.chili@gmail.composted:
Quote:
>On Aug 25, 1:46 pm, Fred <F...@notspam.notwrote:
Quote:
>I'm researching and I see various approaches, with or without regex. So I'm
>asking for opinions on which is the best - that is, the most thorough. Thanks.
>
>Unless your have AJAX as an option, I found REGEX to be the best
>solution.
>Ajax could be bether when you need to check if the domain and account
>is valid on the mailserver.
Outside this room, it is not possible at present to tell which merlyn E-
mail addresses, for example spam0835@merlyn.demon.co.uk, are currently
valid.

World-wide, there must be millions of abandoned E-mail addresses, ones
which technically accept mail that will never be read.

The only trustworthy indication of E-address validity is to receive a
plausible reply to the content of a message sent to it; and that does
not prove continued validity.

False rejections prevent legitimate communication; there must be many
examples of "validators" in books and on the Web which insist in a 2-/3-
character final part :-(.

The only sensible test is one designed to verify that the string could
be grammatically valid, for example that there is at least one character
before an @, followed by at least one character, a dot, and at least one
character.

To do much more requires a full understanding of all applicable RFCs,
including new ones when they appear.

A well-designed system will allow such as
comment <address>
& address (comment)
though few examples are to be found.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Dr J R Stockton
Guest
 
Posts: n/a
#11: Aug 26 '08

re: best email validator


In comp.lang.javascript message <a09acfe7-0e45-452a-8900-2b207905cc76@q5
g2000prf.googlegroups.com>, Tue, 26 Aug 2008 04:50:23, Bart Van der
Donck <bart@nijlen.composted:
Quote:
>
>I would not allow aa/bb@test.com, because slash is often used as
>directory separator to store mail.
My notoriously standards-compliant mailer considers it acceptable. If a
mail receiving agent allows the creation of names of that form, it must
consider any consequent problems. Turnpike won't care; it does not
store mail in that sort of way.

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Closed Thread