Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

valid email address

Hi experts,

I am working on valuating email address functionality in java.

Are these considered valid email addresses?

test@gmail.com,,,
test@yahoo.com...

thx
0
dkim18
Asked:
dkim18
1 Solution
 
for_yanCommented:

Sure these are OK:
test@gmail.com
test@yahoo.com

0
 
for_yanCommented:
Are you talking about dots and commas after the address?
If so, they should not be there
0
 
dkim18Author Commented:
test@gmail.com,,,
test@yahoo.com...

commas and periiods after "com"
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
for_yanCommented:
no, they should not be there
0
 
for_yanCommented:
I tried to sedn form my outlook and got different errors in bothe cases
0
 
for_yanCommented:
With dots it tried to send and bounced nack as it thought dots to be part of the address
0
 
for_yanCommented:
with commas it though that I have a bunch of ore empty addresses and Ourtlook diodn't send it asking what are those additional addresses in an popup window
0
 
n2fcCommented:
Valid if you leave off the trailing ,,, and ...
0
 
for_yanCommented:
This is quite expected befhaviour - you definitely want to get rid of dots and commas
0
 
dkim18Author Commented:
How come this code doesn't catch that?

try {
                      new javax.mail.internet.InternetAddress(email, true);
                      } catch (javax.mail.internet.AddressException e) {
                            ....

                      }                
                }
0
 
for_yanCommented:
I don't think
javax.mail.internet.InternetAddress(email)
makes very deep check

Better to exclude these dots and commas - most mailers will have problems with it

dots definitley - they are legitimate simbols - but they modify email address making it incorrect

this

test@gmail.com,,,

is juts like one valid address plus two empty addresses
and then the handling program may choose to ignore empty onese or complain
 
0
 
CEHJCommented:
The best (and probably only way ultimately) to test an address is to send a mail to it
0
 
for_yanCommented:
And that's what I did, CEHJ,  - see above.
0
 
for_yanCommented:
Actually dots do cause exception:
                         try{
        InternetAddress inad = new InternetAddress("test@gmail.com...");
                              }catch(Exception ex){
                                  ex.printStackTrace();
                              }

Open in new window


javax.mail.internet.AddressException: Domain contains dot-dot in string ``test@gmail.com...''
	at javax.mail.internet.InternetAddress.checkAddress(InternetAddress.java:1272)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:1091)
	at javax.mail.internet.InternetAddress.parse(InternetAddress.java:633)
 ....

Open in new window


Commas do not, as I guess it fiirst parses out the address.
But this is waht does InternetAddress constructir - in other places it may not work
this way

0
 
dkim18Author Commented:
this worked and this is good enough for now.

String regex = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[_A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*\\.(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)";

thanks for_yan
0
 
for_yanCommented:

In the book Regular Expression Cookbook, that's what they recommend for validating Email
addresses:

^[\w!#$%&'*+/=?`{|}~^-]+(?:\.[!#$%&'*+/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}$
Regex options: Case insensitive
Regex flavors: .NET, Java, JavaScript, PCRE, Perl, Python

\A[\w!#$%&'*+/=?`{|}~^-]+(?:\.[!#$%&'*+/=?`{|}~^-]+)*@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}\Z
Regex options: Case insensitive
Regex flavors: .NET, Java, PCRE, Perl, Python, Ruby

Open in new window


With Java any of the two variants above should work.
0
 
for_yanCommented:
I guess in that biook they are ignoring necessity of doubling backslashes in Java
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now