473,671 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best email validator

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.
Aug 25 '08 #1
10 1496
On Aug 25, 1:46 pm, Fred <F...@notspam.n otwrote:
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
Aug 25 '08 #2
In comp.lang.javas cript message <g8**********@a ioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <Fr**@notspam.n otposted:
>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 <Fr**@notspam.c om is or will be a deliverable E-mail
address, the exercise has no practical use.

<URL:http://www.merlyn.demo n.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.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 25 '08 #3
On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
In comp.lang.javas cript message <g8unlf$u3...@a ioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.n otposted:
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.c om is or will be a deliverable E-mail
address, the exercise has no practical use.

<URL:http://www.merlyn.demo n.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.dem on.co.uk IE7 FF2 Op9 Sf3
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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|e du|int|mil|gov| arpa|biz|aero|n ame|
coop|info|pro|m useum|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=emai lStr.match(emai lPat);

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

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

var IPArray=domain. match(ipDomainP at);
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.s plit(".");
var len=domArr.leng th;
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(knownDo msPat)==-1)
{
//alert("The domain name extension is invalid");
valid = false;
}
if (len<2)
{
//alert("The address is missing a hostname.");
valid = false;
}
}
return valid;
}
Aug 26 '08 #4
On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
In comp.lang.javas cript message <g8unlf$u3...@a ioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.n otposted:
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.c om is or will be a deliverable E-mail
address, the exercise has no practical use.

<URL:http://www.merlyn.demo n.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.dem on.co.uk IE7 FF2 Op9 Sf3
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.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.
Aug 26 '08 #5
On Aug 25, 9:18 pm, Dr J R Stockton <j...@merlyn.de mon.co.ukwrote:
In comp.lang.javas cript message <g8unlf$u3...@a ioe.org>, Mon, 25 Aug
2008 12:46:36, Fred <F...@notspam.n otposted:
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.c om is or will be a deliverable E-mail
address, the exercise has no practical use.

<URL:http://www.merlyn.demo n.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.dem on.co.uk IE7 FF2 Op9 Sf3
news:comp.lang. javascript FAQ <URL:http://www.jibbering.c om/faq/index.html>.
<URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
AJAX not AJEX
Aug 26 '08 #6
Laser Lips wrote:
function emailCheck(e)
{
* * * * var emailStr;
* * * * emailStr = e;
* * * * valid = true;

* * * * var checkTLD=0;
* * * * var knownDomsPat=/^(com|net|org|e du|int|mil|gov| arpa|biz|aero|n ame|
coop|info|pro|m useum|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=emai lStr.match(emai lPat);

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

* * * * * * * * for (i=0; i<user.length; i++)
* * * * * * * * {
* * * * * * * * * * * * if (user.charCodeA t(i)>127)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * //alert("The username contains invalid Characters.");
* * * * * * * * * * * * * * * * valid =false;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * for (i=0; i<domain.length ; i++)
* * * * * * * * {
* * * * * * * * * * * * if (domain.charCod eAt(i)>127)
* * * * * * * * * * * * {
* * * * * * * * * * * * * * * * //alert("The domain dame contains invalid characters.");
* * * * * * * * * * * * * * * * valid =false;
* * * * * * * * * * * * }
* * * * * * * * }
* * * * * * * * if (user.match(use rPat)==null)
* * * * * * * * {
* * * * * * * * * * * * //alert("The username is invalid.");
* * * * * * * * * * * * valid = false;
* * * * * * * * }

* * * * * * * * var IPArray=domain. match(ipDomainP at);
* * * * * * * * 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.s plit(".");
* * * * * * * * var len=domArr.leng th;
* * * * * * * * 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(knownDo msPat)==-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.charCode At(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
Aug 26 '08 #7
Bart Van der Donck wrote:
Laser Lips wrote:
>function emailCheck(e) {
[...]
}

Nice code.
For fitting values of "nice".
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.
[...]
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.
[...] Note that Windows Hotmail only allows alphanumerics, dot (.),
underscore (_) and hyphen (-) for the full address.
That is good to know, thanks.
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
Aug 26 '08 #8
On Aug 26, 1:06 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Bart Van der Donck wrote:
Laser Lips wrote:
function emailCheck(e) {
[...]
}
Nice code.

For fitting values of "nice".
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.
[...]

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.
[...] Note that Windows Hotmail only allows alphanumerics, dot (.),
underscore (_) and hyphen (-) for the full address.

That is good to know, thanks.
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.
Aug 26 '08 #9
In comp.lang.javas cript message <cf5469cd-9131-4c85-b83f-53effaa0bad6@m4
4g2000hsc.googl egroups.com>, Mon, 25 Aug 2008 10:32:18, Thiago Macedo
<th**********@g mail.composted:
>On Aug 25, 1:46 pm, Fred <F...@notspam.n otwrote:
>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 sp******@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.demo n.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)
Aug 26 '08 #10

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

Similar topics

13
2618
by: Monty | last post by:
I've been searching for guidance on which of the approaches used for skipping repetive links (e.g., link as normal text, link as alt text on invisible image, link with same forground and background colors that becomes visible when in hover or active state using css) is the best approach. Is there any place on the net where this is addressed? Thanks in advance.
131
21639
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately get some good real world examples. Fire away! :) Regards, Peter Foti
4
1664
by: Philipp Lenssen | last post by:
I created a new service: FindForward Backlinks Alerts. You need to include the following HTML in your page (one line, replace with your email)... <script type="text/javascript" src="http://www.findforward.com/backlinks/?email=john@example.com"> </script> .... to then get email whenever someone links to you! In-depth information can be found at
2
1419
by: Al Franz | last post by:
Want to create a template that will have Top, Side and Bottom common HTML code for all pages in a directory. What is the best way to do this, using CSS, Frames or something else. Any chance someone could point me to a good example of this.
1
2069
by: johnmack | last post by:
In my XML instances I want to use the XLink namespace for attributes on certain elements. I'm having quite a hard time determining how to reflect this properly in my DTD and XML instances. In my instance, to declare the namespace, I have this on my root element: <root xmlns:xlink="http://www.w3.org/1999/xlink"> ... <mylink xlink:href="http://foo.com"> ....
0
4221
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET Applications and owner of Access Microsystems. Doug can be reached at doug@accessmicrosystems.com. --------------------------------------------------------------------------------
2
1704
by: gdaalf | last post by:
Folks, Maybe a newbie issue, but I do not quite understand why http://test.aces.uiuc.edu/news/RSS/AcesNewsRSS1.xml will not validate on RSS validator (http://validator.w3.org/feed/). It falls over on line 32, which is <author>dude@uiuc.com The Dude</author> I am not seeing the obvious here. Can some one point it out please?
5
1518
by: TS | last post by:
I have a custom textbox that i need to access a label's text property. the label and textbox are 2 separate controls that will be on my page. Inside my custom control i want to have access to this label's text. I was thinking of having a property on my textbox that was something like LabelControlID. the textbox could then do a .Findcontrol on its parent control to find this label and access its text. i thought that this might be an...
5
1868
by: Ganesh | last post by:
Hi There, I need to validate email address with regular expression control, i tried something like this ^+*@*\.*$ but i need to validate even if it is blank, it should say invalid email, but don't want to use another requirefield validator
0
8483
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8402
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5703
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.