| 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
|
|
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: 16487
|
|
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.)
|
 |
 |
|
|
subject: regexp on email address
|
|
|