All Projects → tallesl → net-EmailAddress

tallesl / net-EmailAddress

Licence: other
Multiple implementations on email address validation.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to net-EmailAddress

Fo Dicom
Fellow Oak DICOM for .NET, .NET Core, Universal Windows, Android, iOS, Mono and Unity
Stars: ✭ 674 (+5516.67%)
Mutual labels:  nuget, dot-net
net-Socket
A minimalist wrapper around System.Net.Sockets.Socket.
Stars: ✭ 21 (+75%)
Mutual labels:  nuget, dot-net
Goldeneye
The CQRS flavoured framework that will speed up your WebAPI and Microservices development
Stars: ✭ 171 (+1325%)
Mutual labels:  nuget, dot-net
CreatingPlatformPlugins
A set of examples and documentation to aid in the development of cross-platform libraries and plugins.
Stars: ✭ 48 (+300%)
Mutual labels:  nuget, dot-net
Fluenttc
🌊 👬 🏢 Integrate with TeamCity fluently
Stars: ✭ 42 (+250%)
Mutual labels:  nuget, dot-net
Dotnetcore
.NET 5 Nuget Packages.
Stars: ✭ 146 (+1116.67%)
Mutual labels:  nuget, dot-net
taxjar.net
Sales Tax API Client for .NET / C#
Stars: ✭ 21 (+75%)
Mutual labels:  nuget, dot-net
SpiceSharp
Spice# is a cross-platform electronic circuit simulator based on Berkeley Spice - the mother of commercial industry-standard circuit simulators.
Stars: ✭ 146 (+1116.67%)
Mutual labels:  nuget
EmptyLicensesLicx
Easy continuous integration of apps using third-party controls that rely on licenses.licx files
Stars: ✭ 57 (+375%)
Mutual labels:  nuget
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-8.33%)
Mutual labels:  nuget
forge
ISC Forge is an open source DHCP conformance validation framework, primarily used for testing ISC Kea.
Stars: ✭ 26 (+116.67%)
Mutual labels:  rfc
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (+91.67%)
Mutual labels:  nuget
Xamarin-Sidebar
A slideout navigation control for Xamarin.iOS
Stars: ✭ 113 (+841.67%)
Mutual labels:  nuget
HtmlRuleSanitizer
A rule based HTML sanitizer built on top of the HTML Agility pack
Stars: ✭ 56 (+366.67%)
Mutual labels:  nuget
MessageBox.Avalonia
Messagebox for AvaloniaUI
Stars: ✭ 222 (+1750%)
Mutual labels:  nuget
aarbac
An Automated Role Based Access Control .NET framework with T-SQL Query Parser which automatically parse select, insert, update, delete queries based on the logged in user role
Stars: ✭ 18 (+50%)
Mutual labels:  nuget
Standard-Toolkit
An update to Component factory's krypton toolkit to support .NET Framework 4.6.2 - 4.8.1 to .NET Core/.NET
Stars: ✭ 194 (+1516.67%)
Mutual labels:  nuget
Apos.Shapes
Shape rendering in MonoGame.
Stars: ✭ 21 (+75%)
Mutual labels:  nuget
Xamarin.iOS.DGActivityIndicatorView
🔰 DGActivityIndicatorView is a collection of nice loading animations for Xamarin.iOS.
Stars: ✭ 28 (+133.33%)
Mutual labels:  nuget
BingMapsSDSToolkit
This toolkit makes it easy to use the Bing Maps Spatial Data Services (SDS) in .NET
Stars: ✭ 39 (+225%)
Mutual labels:  nuget

logo

EmailAddress

MSDN, Reference Source, Phil Haack and JStedfast implementations on email address validation.

Usage

using EmailAddressLibrary;

EmailAddressValidator.Msdn("[email protected]");            // True
EmailAddressValidator.ReferenceSource("[email protected]"); // True
EmailAddressValidator.Haacked("[email protected]");         // True
EmailAddressValidator.JStedfast("[email protected]");       // True

Word of warning

It's not perfect (and probably no email address validation code will ever be).

False negatives:

  • MSDN: 1 2 3
  • Reference Source: 1 2
  • Haacked: 1 2 3

False positives:

  • MSDN: 1 2
  • Reference Source: 1 2
  • Haacked: 1 2

Reference Source

Here's what I did with the Reference Source implementation:

  1. Downloaded Reference Source (version 4.5.2)
  2. Copied MailAddressParser.cs and its dependencies:
  1. Adapted the MailAddressParser class:
  • Changed its access to public
  • Changed MailAddressParser(string data) to public
  • Removed ParseMultipleAddresses(string data)
  • Changed both ParseAddress(string data) and ParseAddress(string data, bool expectMultipleAddresses, ref int index) to void
  1. Fixed missing SR:

Dear Diary

No soup package for you

To validate an email address... should be easy, right? C'mon, we saw those everywhere.

I bet there's a great NuGet package out there waiting for me.

(searches NuGet)

Okay, no package. That was a let down.

Fuck it, we'll do it live

Let's make one, how hard could it be? After all an address is just "local part + @ + domain part". And I'm going to man up and go straight to the RFC, no Wikipedia or Stack Overflow, that's kid stuff.

(reads RFC)

Shit. A email with a space is valid if you precede it with a backslash. Same for an "at" sign. Now you are telling me that I can surround part of the local part with quotes, where there's no need for backslash.

"dear programmer, good luck h@h@"@somedomain.com is valid. I'm out.

And looks like I'm not alone: 1 2 3. Ah, and by the way, here is one regex I found:

/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5
C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\
x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:
\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn
--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:
(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a
-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})
(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|
(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD 

Strike one

Searching around for an algorithm I found this MSDN snippet. MSDN is Microsoft, these guys probably know what they're doing.

(reads code)

Yuck, look at that. The thing isn't even thread safe: there's an invalid field being read/written in each call (state is bad, mmkay?).

But hey, nobody's perfect. Since it's just for this little utility of mine (and not a production system), let's fix the thread safety, create the package and call it a day.

Strike two

Guess what? Now I have to use the thing in a production system™. And, to my surprise, there's a first issue (!). Of course, the surprise is not that there's an issue with the code (not at all), it's that there's someone else besides me using this little thing.

That MSDN code is bad and I'm not in the mood of writing such a beast of a parser. What now?

Wait a second. MailAddress does this already (throws when it's invalid). I even forgot that I've grumbled about it before on my blog.

Ah, open source is a beautiful thing. There's an internal class called MailAddressParser just for that. Let's borrow it.

(reads MailAddressParser.cs)

Sadly, it interfaces with outside code through exceptions (FormatException to be more precise). It's bad from the optimization side, since exception handling is not very performatic (when used with high volume stuff might be an issue) and also bad from the philosophical side, after all finding format errors is the whole point of the class (nothing exceptional there). But that's just me being picky.

Strike three, I'm out

So there's a second issue. Yep, validating email address is a lost battle.

So in this (last) version I've put several implementations for you to choose, the first one (MSDN), the second one (Reference Source) and also Phil Haack and JStedfast implementations.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].