Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsValidEmail() Improved Regex Pattern #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Huntk23
Copy link

@Huntk23 Huntk23 commented Dec 17, 2019

Made a slight update to the Regex Pattern to conform more to the rules of RFC 5322 which obsoletes RFC 2822.

I ended up updating the regex pattern because the built in .NET MailAddressParser conforms to RC2822 and did not want to re-implement to conform to RC5322. The supplied regex pattern should match ~99% of valid emails.

More tests have been implemented.

Old regex pattern:

--- Valid Email List ---
True : email@example.com
True : firstname.lastname@example.com
True : email@subdomain.example.com
False : firstname+lastname@example.com
True : email@123.123.123.123
True : email@[123.123.123.123]
True : 1234567890@example.com
True : email@example-one.com
True : _______@example.com
True : email@example.name
True : email@example.museum
True : email@example.co.jp
True : firstname-lastname@example.com

--- Invalid Email List ---
False : plainaddress
False : #@%^%#$@#$@#.com
False : @example.com
False : Joe Smith <email@example.com>
False : email.example.com
False : email@example@example.com
True : .email@example.com
True : email.@example.com
True : email..email@example.com
False : email@example.com (Joe Smith)
False : email@example
True : email@-example.com
False : email@example..com
True : Abc..123@example.com

New regex pattern:

--- Valid Email List ---
True : email@example.com
True : firstname.lastname@example.com
True : email@subdomain.example.com
True : firstname+lastname@example.com
True : email@123.123.123.123
True : email@[123.123.123.123]
True : 1234567890@example.com
True : email@example-one.com
True : _______@example.com
True : email@example.name
True : email@example.museum
True : email@example.co.jp
True : firstname-lastname@example.com

--- Invalid Email List ---
False : plainaddress
False : #@%^%#$@#$@#.com
False : @example.com
False : Joe Smith <email@example.com>
False : email.example.com
False : email@example@example.com
False : .email@example.com
False : email.@example.com
False : email..email@example.com
False : email@example.com (Joe Smith)
False : email@example
False : email@-example.com
False : email@example..com
False : Abc..123@example.com

For curiosities sake;

MailAddress constructor try/catch:

--- Valid Email List ---
True : email@example.com
True : firstname.lastname@example.com
True : email@subdomain.example.com
True : firstname+lastname@example.com
True : email@123.123.123.123
True : email@[123.123.123.123]
True : 1234567890@example.com
True : email@example-one.com
True : _______@example.com
True : email@example.name
True : email@example.museum
True : email@example.co.jp
True : firstname-lastname@example.com

--- Invalid Email List ---
False : plainaddress
False : #@%^%#$@#$@#.com
False : @example.com
True: Joe Smith <email@example.com>
False : email.example.com
False : email@example@example.com
False : .email@example.com
True : email.@example.com
True : email..email@example.com
True : email@example.com (Joe Smith)
True : email@example
True : email@-example.com
True : email@example..com
True : Abc..123@example.com

Fixes #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

.IsValidEmail() reporting incorrect results
1 participant