472,101 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Reg Expression - valid International email addresses?

Can anyone please help me with a regular expression
to test for Valid International Email Addresses?
Also, which version of javascript (1.2 ?) is needed for same?

Thanks.
Regards.
Jul 20 '05 #1
14 8194
nagual wrote:
Can anyone please help me with a regular expression
to test for Valid International Email Addresses?


Yes, I know this says "Perl", not "JavaScript" but read it anyway. OK?

http://www.perldoc.com/perl5.8.0/pod...-mail-address-

--
David Dorward http://david.us-lot.org/
Redesign in progress: http://stone.thecoreworlds.net/
Microsoft announces IE is dead (so upgrade):
http://minutillo.com/steve/weblog/20...ces-ie-is-dead
Jul 20 '05 #2
The following uses regular expressions adapted from Jeffery Friedl's
book to check the format of an email string.

rxEmail =
/^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.(?:com|edu|biz|org|gov|int|inf
o|mil|net|name|museum|coop|aero|[a-z][a-z])\b/;

Convert to lower case before testing.

rxEmail.test(email.toLowerCase());

Note that the pattern used non-capture parenthesis which are available
in IE5.5+ and JavaScript 1.5. For older browsers like NN4 replace (?: by
( in the above expression.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
On 12 Jul 2003 16:27:45 GMT, Mark Szlazak <an*******@devdex.com>
wrote:
The following uses regular expressions adapted from Jeffery Friedl's
book to check the format of an email string.

rxEmail =
/^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.(?:com|edu|biz|org|gov|int|inf
o|mil|net|name|museum|coop|aero|[a-z][a-z])\b/;

Convert to lower case before testing.

rxEmail.test(email.toLowerCase());

Note that the pattern used non-capture parenthesis which are available
in IE5.5+ and JavaScript 1.5. For older browsers like NN4 replace (?: by
( in the above expression.


My email address has a + in it, you don't seem to list that one
above...

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4
Well, then just put the + in.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
Mark Szlazak wrote on 12 jul 2003 in comp.lang.javascript:
Forgot one thing. If you only want international emails then modify the
regex to:

rxEmail =/^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.[a-z][a-z]\b/;


..int

as in:

http://www.who.int/

is THE international domain postfix.
..uk, .nl, .ca, etc are the NATIONAL ones
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #6
On 13 Jul 2003 04:37:37 GMT, Mark Szlazak <an*******@devdex.com>
wrote:
Well, then just put the + in.


and all the thousands of other legal characters... that's the problem
you're missing. I wouldn't bother with the validation at all... as
all you'll do is get a junk valid-looking email address, rather than
simply an incorrect one.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #7
If your seeking perfection and want to get all those "thousands" of
emails then speak to God.
I'm sticking with pragmatic solutions.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8
On 13 Jul 2003 14:57:45 GMT, Mark Szlazak <an*******@devdex.com>
wrote:
If your seeking perfection and want to get all those "thousands" of
emails then speak to God.
I'm sticking with pragmatic solutions.


Because of the + in my email address being rejected, I've not done
over 3000 UKP worth of online business with various online agencies
this year (mostly computer equipment and travel.) now you may be
happy to throw away that business, after all I'm just one bloke right?
but are your clients fully aware?

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9
JRS: In article <3f*********************@news.frii.net>, seen in
news:comp.lang.javascript, Mark Szlazak <ms******@aol.com> posted at
Sat, 12 Jul 2003 21:07:39 :-
Forgot one thing. If you only want international emails then modify the
regex to:

rxEmail =/^\w[-.\w]*\@[-a-b0-9]+(?:\.[-a-b0-9]+)*\.[a-z][a-z]\b/;


International does not mean foreign; it includes America. Indeed, the
OP seems to be Australian. Some US E-mail addresses end, I believe, in
..us, as is right and proper. Many non-US ones end in .com or .net, too.

The existence of a national indication in most cases implies a
significant connection with that country, with certain well-known
exceptions; the converse is not true.

Don't believe all that you read in books; even if it was good when
written, which is uncertain, the facts might have changed.

There is little point in doing much validation on an E-address.

It is *impossible* to tell, other than by hearing of delivery, that an
E-address is deliverable to; I can change the rules at this site while
not connected to the Net. Attempted exact validation risks false
negatives (so it needs to be possible to send to an address that the
test actually rejects) and false over-confidence.

ISTM that the only reasonable validation is one checking that the field
is non-empty and that its contents match the minimum requirements; that
will deal with cases where some other piece of information is entered.

/.+@/+\..+/ seems about as strong a test as is appropriate; if I have
it right, check for something @ something . something .

E-address validation must be a FAQ candidate; it could provide a basis
for an entry on RegExps.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #10
The pattern with + is just one. I'm still waiting on those thousands.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #11
Mark Szlazak wrote:
The pattern with + is just one. I'm still waiting on those thousands.

I think the idea is to build an array of every singly possible valid email
address. How long is an email address aloud to be? 255 characters for the
name part?, then 255 characters for the domain name part?...

so, all you need to do is build an array with
4.653138834498368145776998455562e+613 elements, then check if the inputted
email address is in taht array.
Simple.

Jul 20 '05 #12
On 14 Jul 2003 01:17:35 GMT, Mark Szlazak <an*******@devdex.com>
wrote:
The pattern with + is just one. I'm still waiting on those thousands.


You've already been given the link to the perl faq which contains a
RegExp many hundreds of chars long which is still not enough.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #13
On 14 Jul 2003 01:17:35 GMT, Mark Szlazak <an*******@devdex.com>
wrote:
The pattern with + is just one. I'm still waiting on those thousands.


Underscore (_) for starters. 1999 more to go.

The point is that even with a perfect regular expression, you don't
have any idea whether the address is valid or not. It is impossible
to determine unless you send mail to the account and get a response
from the person. By attempting to validate the email address, all you
do is risk disallowing valid addresses. If you're going to do any
validation at all just check whether there is a @ and a subsequent .
character.

Whenever I sign up for something and I don't really want mail I always
use my old ISP's "bitbucket" address because the incoming mail goes
directly into the NUL device. It's very efficient.

Regards,
Steve
Jul 20 '05 #14
Two of my responses haven't posted over the last two days so I'll post
again and address Jim, John and Steve.

Jim now points to Tom's large regex and says that's still not enough.
Well it actually could be too much for someone else since patterns
may never occur in the wild! People may just be interested in whats
out there and if a simple regex email format validator good enough!

John talks about this when he mentions a topic related to reliability.
If a simple format checker is 99.99 percent reliable then what is the
significance of those false negatives? It maybe none. He also provides
a simple overall pattern but the OP may needs something more specific
to filter international emails ... whatever that means.

Steve then talks about two issues that are related but seperate. There
is the issue of a valid general email format and then the issue of
whether a specific instant of it exists.

I would be interested in some empirical data on what's out there and
how that has changed over time versus what's possible via specs.

Thanks.
Jul 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hoang | last post: by
9 posts views Thread by Holden Caulfield | last post: by
2 posts views Thread by Bryce Budd | last post: by
6 posts views Thread by JohnSouth | last post: by
2 posts views Thread by Ramesh | last post: by

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.