This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes java regex 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 "java regex email validation" Watch "java regex email validation" New topic
Author

java regex email validation

imran sujoy
Greenhorn

Joined: Sep 02, 2008
Posts: 9
I have a requirement of validating email field. Most of the things are done. But I'm stuck at one place. The email allows _, +, . only once in the username part (i.e. before @), once or more, but never consecutively. Also, . can't be immediately before or after @. I couldn't do that checking for consecutive dots or pluses. How to add with \\w a dot or a plus? Can somebody kindly help? Thanks in advance.


Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
I'd do with the org.apache.commons.validator.EmailValidator class.


Ping & DNS - my free Android networking tools app
imran sujoy
Greenhorn

Joined: Sep 02, 2008
Posts: 9
Thanks for the reply Ulf, but I'm not sure how much EmailValidator class will help when one needs a custom validator (like in my case + allowed, but ... not allowed, though the 2nd one is a perfectly valid email IMO). Anyway, just after posting here I got the solution myself:



The () in place of [] did the trick actually.

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
It's generally not a good idea to fail email validation for valid addresses. If an address is good enough for the relevant RFCs, then it should be good enough for you application. Also note that the regexp will fail I18N domain names.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java regex email validation