Java validating email address

I'm Nataraja Gootooru, programmer by profession and passionate about technologies.All examples given here are as simple as possible to help beginners.Here’s a Java example to show you how to use regex to validate email address. [email protected], [email protected], [email protected] [email protected], [email protected], [email protected] 3. [email protected]%*– email’s tld is only allow character and digit 9. [email protected]– email’s last character can not end with dot “.” 11. [email protected] -email’s tld which has two characters can not contains digit Here’s a unit test using test NG.List emails = new Array List(); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("[email protected]"); emails.add("user? : false [email protected]: false Now lets modify the regex such that domain name must include at least one dot, and that the part of the domain name after the last dot can only consist of letters. The top-level domain (in these examples) must consist of two to six letters only.

In the last post, I explained about java regular expression in detail with some examples.

I recommend you the excellent web site to start learning regex But your regex does not seems good. here is the bad code : [.[a-z A-Z_0-9]*] You need to use instead of * in some part of your regex, etc.

validating email with regex is explained here (I recommend you to read it and use one of their regex instead of yours) : yeah, that website.

Note that the page you link to says this, essentially: "This regex validates all valid e-mail addresses (btw, when I say 'all e-mail addresses', I mean 'everything matched by this regex'; I don't give a damn that actual valid e-mail address not matching this exist)." Circular reasoning at its finest.

Apache Commons is generally known as a solid project.