I am working on email Validation using java having RFC 2821 in mind. I have used following code to validate all my email address:
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
Java api says its RFC-822 compliant. Is there a much difference between RFC 2821 and 822?
Also the above api is failing to validate email in below cases:
var@yahoo
- validation returns true, but it is invalid emailvar(comment)@yahoo.com
- validation returns false, but it is valid email
Can you tell me any work around for this to get it done.
Looks to me that you want to validate email ids that are used nowadays and not really to be compliant to any RFC. For our project we made our own very simple email validator. Why ? The apache and java mail one use regex and there are some cases (I do not know which as we were not printing the email's in the log) that make regex go in to a forever loop. This means the client handler thread goes into a loop and the user sees a blank screen!
So what we do is essentially allow new email ids like they would look like at sites like google/ yahoo.
Meaning [email protected]
What we check for At most 1 @ Check for 1 or more chars before @ After @ have some chars + one dot atleast + chrs after dot
Did not get any complaints for the last two years. Also most of the times you need to send the person an email to make sure the domain exists etc and a link with a unique token (sign up confirm) to make sure the person owns the email id (with a message to real owner to only click if they came to your site)