What is the most elegant code to validate that a string is a valid email address?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
To be honest, in production code, the best I do is check for an
@
symbol.I'm never in a place to be completely validating emails. You know how I see if it was really valid? If it got sent. If it didn't, it's bad, if it did, life's good. That's all I need to know.
I ended up using this regex, as it successfully validates commas, comments, Unicode characters and IP(v4) domain addresses.
Valid addresses will be:
Based on the answer of @Cogwheel i want to share a modified solution that works for SSIS and the "Script Component":
Place this code in the right method:
Then you can use a Conditional Split to filter out all invalid records or whatever you want to do.
/Using the Internal Regex used in creating the "new EmailAddressAttribute();" component in .Net4.5 >>> using System.ComponentModel.DataAnnotations; //To Validate an Email Address......Tested and Working.
Also, You can use this:
http://msdn.microsoft.com/en-us/library/01escwtf(v=vs.110).aspx
Check email string is right format or wrong format by
System.Text.RegularExpressions
: