Thursday, March 13, 2008

email regex that doesnt suck

why is it so hard to find a good email java regex on google? They all suck.

Here are a few regexes that i would use in a production system to check if an email is valid:

"([\\w-]+(?:\\.[\\w-]+)*@(?:[\\w-]+\\.)+\\w{2,7})\\b"


Something a little more light weight:

"[^\\s]+@[^\\s]+([.]\\w{2,3})+"


and if all else fails, this might be useful:
Apache Commons EmailValidator class API

3 comments:

  1. http://www.regular-expressions.info/email.html

    ReplyDelete
  2. thanks for the link, i havent been there in a while, but as i recall its a trustworthy resource

    ReplyDelete