I was looking at a way to create a perfect (or near to perfect) means to check if an email is valid...

Though I have been learning the concept and tricks of regular expressions, I was wondering if it was better to create a custom-means to check if an email is valid using for-loops and comparison checks. I ask this, because after looking at wikipedia's interpretation of valid and invalid emails,http://en.wikipedia.org/wiki/Email_address , the regular expression may be rather complex.

@Neil - That regex is no longer accurate. Top-level domain names can now be longer than 4 characters (e.g. mydomain.museum), and email addresses can contain unicode characters like δοκιμή@παράδειγμα.δοκιμή, as well as any of !#$%&'*+-/=?^_`{|}~.
–
Justin MorganApr 18 '12 at 15:16

It is completely overkill. Doing this in "normal" code will also be long for absolutely nothing. You don't need to validate for perfect email addresses. You also don't need to worry about speed / efficiency. This is called premature optimization, and you shouldn't do it. You're just wasting your time with little things like this when you should be working on your app / project itself.

Consider replacing a-z0-9_ with \w to account for non-Latin characters like δοκιμή@παράδειγμα.δοκιμή, which are now allowed.
–
Justin MorganApr 18 '12 at 15:19

1

I'm not immune to that myself, but I gave it a go. This version will allow _ in a few places that previously required [a-zA-Z0-9], but I chose simplicity.
–
Justin MorganApr 18 '12 at 16:06

I know its been a while since I replied to this posting, yet I have read everyone's response and did a bit of studying on my behalf and I would like to thank everyone for the input and insightful guidance. It is very much appreciated - thank you all :D I think keeping it simple will suffice for the purpose of the current goal.
–
CraigMay 8 '12 at 8:35