File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Jakarta RegExp - Email Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jakarta RegExp - Email Validation" Watch "Jakarta RegExp - Email Validation" New topic
Author

Jakarta RegExp - Email Validation

SAM KUMAR
Greenhorn

Joined: Jan 02, 2002
Posts: 25
Hi,

I am looking for email validation regular expression using org.apache.regexp.RE?

Also, where can I find document describing email address specification?


Thanks.

SK
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
it's not entirely clear from your question what you want to do, but i'm assuming you're talking about e-mail addresses. trying to validate entire e-mail messages with a regular expression wouldn't make much sense, after all.

these days, Internet (SMTP) e-mail addresses are defined in RFC 2822, and you want to look in section 3.4. be aware that the actual syntax is a lot more complex and flexible than it seems at first glance. be aware, also, that not every piece of e-mail sending software in the world is all that strict about what types of things they call an "address", so you may encounter forms that do not fit the definition, and you'll have to try and cope with them.
SAM KUMAR
Greenhorn

Joined: Jan 02, 2002
Posts: 25
Hi,

Thanks for your reply.

Please eloborate why it does not make sense to use reg exp?
"....trying to validate entire e-mail messages with a regular expression wouldn't make much sense, after all."


I am trying to add reg exp which should allow quoted user, for "firstname lastname"@host.com. This is what I have:
RE emailPattern = new RE("((^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9])|([^\"*$\"]))@[a-z-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$");

Thanks.

SK
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

less than a month ago, we had a small discussion here:

http://www.coderanch.com/t/376344/java/java/Regex-email-verifying

- not discussing the RFC
- using javas regexes - I don't know where they differ from jakartas.


http://home.arcor.de/hirnstrom/bewerbung
SAM KUMAR
Greenhorn

Joined: Jan 02, 2002
Posts: 25
Hi:

Thanks for your reply. That was very helpful.

Now I am trying to prevent continous dot's, for ex: test......ing@host.com. Please let me know how do i prevent this using RE.

Beck, please eloborate why it does not make sense to use reg exp? Is there any performance issue?

"....trying to validate entire e-mail messages with a regular expression wouldn't make much sense, after all."


Thanks.

SK
M Beck
Ranch Hand

Joined: Jan 14, 2005
Posts: 323
i'm sorry, i wasn't making myself very clear -- i meant it would not make sense to use regexes to validate an entire e-mail message, as opposed to just the address. my apologies.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Even if you use regular express to validate that the email address is in proper format, you cannot be sure that it is a valid, working, live email address.

The user could always enter addresses such as a@a.com.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
 
wood burning stoves
 
subject: Jakarta RegExp - Email Validation