• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jakarta RegExp - Email Validation

 
SAM KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
SAM KUMAR
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic