validate that an email address contains "@" and "."

r.r picture r.r · May 10, 2011 · Viewed 13.7k times · Source

i need to validate that an inserted email address contains "@" and "." without a regular expression. Can somebody to give me "java code" and "structure chart" examples please?

Answer

Jon Skeet picture Jon Skeet · May 10, 2011

I suspect you're after something like:

if (!address.contains("@") || !address.contains("."))
{
    // Handle bad address
}

EDIT: This is far from a complete validation, of course. It's barely even the start of validation - but hopefully this will get you going with the particular case you wanted to handle.