This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I tried adding the suggested fregment "(?!\.)", but it didn't worked.
Could be the reason that I was not able to add it properly.
Could you please give me full regex?
Joined: Mar 05, 2008
Well, that link you gave uses the Jakarta Regexp package, which is not exactly the same as java.util.regex, which is what I was using. In particular, the Jakarta package does not support any form of lookahead. (Compare org.apache.regexp.RE with java.util.regex.Pattern.) If you want to use Jakarta Regexp, you'll have to use my first suggestion, not the second.
The regex for a full email address validation is very large. I published one in reply # 20 of here but I made it clear that it need a lot more testing before it should be used in production. I wrote that validator to validate RFC821 email addresses. I'm not sure what the latest RFC is but if you are to do it properly you need to find out. Having said that, you still have a problem. A lot of service providers allow email addresses to be outside the official specification so you might reject email addresses that are valid as far as your customer is concerned.
Many others have published email address regex validators of various conformance levels. Google will find them.
So why do you think you need to validate an email address? I used to think it necessary but these days I don't bother. If someone supplies email@example.com your regex might accept it even though it is not going to exist.