One email validator to rule them all

I was digging through an ASP.NET/C# legacy application for a client and came across this gem of validation:

private static bool IsValidEmail(String Email)
    return Email.Contains('@') && Email.Contains('.');

Quick and dirty, sheesh. There are of course many other (and better) ways to check if an email is valid. Some are insane though. For a non-restrictive solution (as I'm sure the author of the above intended) it probably would have been better to use spig's suggestion from the link, /.+@[^@]+\.[^@]{2,}$/. Something, followed by an @, followed by something, followed by a period, followed by at least 2 of something.

Justin Rodermond

Designer & developer. I have a land dolphin named Lois who helps me write Javascript and PHP. You can reach me at

comments powered by Disqus