Validating e-mail address format

It's been asked plenty of times, but the only answer I found to work for me was the use of regular expressions. I was able to get this bit of code to work:

if (!(t_email.getText ()).matches("\\w*\\.\\w*@\\w*\\.\\w*"))//check for valid and existing e-mail

{

JOptionPane.showMessageDialog (CreateAccount.this,"invalid." ,"Error",

JOptionPane.ERROR_MESSAGE);

}

That code accepts e-mail addresses in the format of: eg.tristan.lee@domain.com Anything liketristan@domain.com is considered invalid for that expression.

I figured thatif (!(t_email.getText ()).matches("[a-z[._-][\\d]]*[@][a-z[.][\\d]]*[.][a-z[.][\\d]]*"))//check for valid and existing e-mail

{

JOptionPane.showMessageDialog (CreateAccount.this,"invalid." ,"Error",

JOptionPane.ERROR_MESSAGE);

}

would work, but it says thattristan@domain..com is valid. You can't have 2 periods before the com/net/org, etc can you?

[1367 byte] By [tristanlee85a] at [2007-11-27 5:58:58]
# 1

no you can't,

note that you don't even need a '.' for a valid email address.

just check for an '@' and invalid chars.

if you want to go to town, you can check that each . is prefixed by a valid char.

(note that: foo@hotmail.com.) is valid (iirc) (note trailing dot).

prob.not.sola at 2007-7-12 16:34:46 > top of Java-index,Java Essentials,Java Programming...
# 2
http://www.regular-expressions.info/email.html
jverda at 2007-7-12 16:34:46 > top of Java-index,Java Essentials,Java Programming...
# 3
> http://www.regular-expressions.info/email.htmlindeed.
prob.not.sola at 2007-7-12 16:34:46 > top of Java-index,Java Essentials,Java Programming...