File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes regexp on email address Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "regexp on email address" Watch "regexp on email address" New topic
Author

regexp on email address

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Hi there, I'm having a problem with Regexp and email validation,
I'm using the following code to check if the address is valid or not

It returns true with the followig address:
invalidAdress@test.cxm

but it is rejected by the smtp server.
I'm not very good with regexp, but I guess is the best way to validate an email address.


trying to decode a woman mind....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

That address is valid as per the SMTP specification. Are you trying to catch invalid TLDs? If so, you are not going to be able to do that with a regular expression.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
550 invalidAdress@test.cxm: no such domain

that's the stmp server reply.

What could I use to be sure that the domain would be accepted?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You'll need to try to connect to the domain to see if it exists. So you need a step that happens before you try to send your mail that looks to see if your application can establish aconnection to this resource. See the java.net.* package for a candidate.

This doesn't guarentee success of the mail though. I'm not sure I'd include validation that an email address exists as part of address validation.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

Originally posted by Paul Sturrock:
I'm not sure I'd include validation that an email address exists as part of address validation.
I wouldn't. Even if you can confirm the domain name is correct, and even if you can confirm there is really an SMTP server working in that domain, it's quite likely that it will refuse to tell you whether a particular address is valid. (That's because spammers use dictionary attacks to harvest valid addresses.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: regexp on email address
 
Similar Threads
i am validating email on server side
First hand at RegEx
email validation using java code ."taking space."
Invalid RegEx on @Pattern
Email Address using java regular expression