|
This is HALF answered in the MSDN library with an example function called IsValidEmail. Does anyone else think maybe it's time the example function (which developers are likely to copy-paste) was changed to closer represented what an email address can actually be? Sure, it matches joe.blogs@example.com, or joe-blogs@example.com... But how about joe.blogs+work@example.com, or joe.blogs+support@example.com, or e=mc^2@example.com, or many other valid email addresses? The page http://msdn.microsoft.com/en-us/library/01escwtf.aspx has been updated for each new release of VisualStudio/.NET, but even the VS 2010/.NET4.0 one isn't much better! - Moved bynobugzMVP, ModeratorTuesday, June 02, 2009 11:41 AMnot a clr q (From:Common Language Runtime)
-
| | NastyBastard | I understand your frustration, I don't have a unique email address, but use multiple ones based on the website I am logging into. I have a personal domain that has a catch all for all email addys w/o account. That is how I do something like this msdn_ww@MyDomain.com NYTImes_ww@MyDomain.com Amazon_ww@MyDomain.com That way I know if my email addy has been sold to another company when I receive email from the non originating source, or if a site gets hacked and I start receiving ____ spam. Has happened. The best you can do is add a community comment to the MSDN page specifying what you go through; for in the end its up to the target web developers who are enforcing the bad regex patterns on the users due to ignorance of the situation. Other suggestions
- Possibly create a website specifically for this problem. If you maintain it long enough it might become the first item in the search engines list instead of the bad patterns.
- Put the pattern on the wikipedia page (E-mail address ) which best solves the problem.
GL
William Wegerson ( www.OmegaCoder.Com) - Marked As Answer byNastyBastard Thursday, June 04, 2009 6:38 AM
- Unmarked As Answer byNastyBastard Monday, June 08, 2009 10:17 AM
- Marked As Answer byNastyBastard Tuesday, June 09, 2009 4:27 AM
-
| | OmegaMan | Ah, that brings back memories. I saw a regular expression once that filled an entire printed page, filled with completely inscrutable regexp. The Unix Hater's Handbook about sendmail was a great joy too. It's a lively discussion, you probably can contribute if you are in to that sort of stuff. But it has very little to do with the CLR, the topic of this forum.
Hans Passant. | | nobugz | public static bool isValidEmail(string inputEmail) { string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; Regex re = new Regex(strRegex); if (re.IsMatch(inputEmail)) return (true); else return (false); }
Here we go Regards, Nikolay- Proposed As Answer byTao Liang Tuesday, June 02, 2009 6:52 AM
- Unproposed As Answer byOmegaManMVP, ModeratorTuesday, June 02, 2009 6:32 PM
-
| | Nikolay Podkolzin | I think you've missed the point. All you've really achieved is to allow for an ip address instead of a domain. Whilst useful, that's even less common than some of my examples. If anyone can and cares to update the documentation, something as simple as the following would be a step in the right direction ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$ I lifted it from http://www.regular-expressions.info/email.html. They also have a more comprehensive one closer to RFC 2822, but all I'm looking for personally in this change is that amateur developers who just copy-past the example validation code don't invalidate my joe.bloggs+support@example.com email address. Those who use Gmail probably understand my frustration.. but may not realize it's also supported by other MTAs. | | NastyBastard | ^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$
Doesn't work. Incorrectly reports that joe .. blogs+work@example.com . joe.blogs+work@example.com is a valid addy. Can't have two periods consecutively or a period at the beginning.
William Wegerson ( www.OmegaCoder.Com) | | OmegaMan | I understand this doesn't invalidate all technically-invalid email addresses. But even an email address adhering perfectly to the RFC could still be invalid (i.e. the user doesn't exist, or the domain doesn't have an MX record). I think, if you're not going to match exactly, you should ere on allowing MORE email addresses over FEWER. Because of this example (albeit indirectly) I can't sign up on many websites with my perfectly valid email address. It's an annoyance I often hear from developer peers. Disallowing "+", or "%" is just as arbitrary as disallowing "e" or "t". A very basic email address validation is testing for an @ character. If you don't like the semi complicated ones, why not stick with that? ^.*@.*$ If you're anal about having a complex one that will invalidate on some principles (such as the double period "..") then use one of the more comprehensive ones found at http://www.regular-expressions.info/email.html. | | NastyBastard | I understand your frustration, I don't have a unique email address, but use multiple ones based on the website I am logging into. I have a personal domain that has a catch all for all email addys w/o account. That is how I do something like this msdn_ww@MyDomain.com NYTImes_ww@MyDomain.com Amazon_ww@MyDomain.com That way I know if my email addy has been sold to another company when I receive email from the non originating source, or if a site gets hacked and I start receiving ____ spam. Has happened. The best you can do is add a community comment to the MSDN page specifying what you go through; for in the end its up to the target web developers who are enforcing the bad regex patterns on the users due to ignorance of the situation. Other suggestions
- Possibly create a website specifically for this problem. If you maintain it long enough it might become the first item in the search engines list instead of the bad patterns.
- Put the pattern on the wikipedia page (E-mail address ) which best solves the problem.
GL
William Wegerson ( www.OmegaCoder.Com) - Marked As Answer byNastyBastard Thursday, June 04, 2009 6:38 AM
- Unmarked As Answer byNastyBastard Monday, June 08, 2009 10:17 AM
- Marked As Answer byNastyBastard Tuesday, June 09, 2009 4:27 AM
-
| | OmegaMan | | | OmegaMan | I took your advice and vented on http://gotgeek.co.nz/?p=33. Doing so prompted fellow developers to express equivalent pet peeves from which I can learn so as to not make such mistakes. After enough trolls have helped me fill in all the holes, and weed out the circumlocution and verbosity I hope to end up with a helpful/educational post to which I can refer people. | | NastyBastard | I liked this post so much, for we are getting a few email regex questions. I made it sticky to regex forum for 2010.
William Wegerson ( www.OmegaCoder.Com) | | OmegaMan |
|