• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regexp on email address

 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic