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 protected]
True : [email protected]
True : [email protected]
False : [email protected]
True : [email protected]
True : email@[123.123.123.123]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]

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

New regex pattern:

--- Valid Email List ---
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : email@[123.123.123.123]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]

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

For curiosities sake;

MailAddress constructor try/catch:

--- Valid Email List ---
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : email@[123.123.123.123]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]
True : [email protected]

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

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