File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validity of an email address in Java program.

 
Siddharth Bhargava
Ranch Hand
Posts: 274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,

I am sending an email using JavaMail API. I would like to check the validity of email address which the user gives before forwarding it to the JavaMail API for sending an email.

Please do help me in validating an email address which the user provides either through JavaMail API OR through regular expressions.

Which method is more near to accurate or best ?

Thanks and Regards,
Sid.
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? JavaMail will already throw an exception if you give it a malformed e-mail address. (That was what you meant by "valid", wasn't it?) I don't see why you need to reinvent that wheel.
 
Siddharth Bhargava
Ranch Hand
Posts: 274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Why? JavaMail will already throw an exception if you give it a malformed e-mail address. (That was what you meant by "valid", wasn't it?) I don't see why you need to reinvent that wheel.



What I mean was that when I give an invalid email address abc@sdgdfg.cgrfg then the program validates the email address, gives an error message and gracefully exits the program AND not give a stacktrace in the console or log file.
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you have to be much more careful about what you want. That isn't a malformed e-mail address, so what's wrong with it? I expect you know that "cgrfg" isn't a top-level domain, at least not this month it isn't. So let's suppose that you had "abc@sdgdfg.com". Is that valid? Why, or why not?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic