• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validity of an email address in Java program.

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic