• 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

regexp on email address

 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28261
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

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.)
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic