Reg Expression - valid International email addresses?

N

nagual

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.
 
M

Mark Szlazak

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.
 
J

Jim Ley

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.
 
E

Evertjan.

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
 
J

Jim Ley

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.
 
M

Mark Szlazak

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

Jim Ley

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.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
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.
 
D

Disco

Mark said:
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.
 
J

Jim Ley

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.
 
S

Steve van Dongen

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
 
M

Mark Szlazak

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top