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 issue #41743

Closed
tcoakley opened this issue Jul 12, 2024 · 1 comment
Closed

IsValidEmail issue #41743

tcoakley opened this issue Jul 12, 2024 · 1 comment
Assignees
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-fundamentals/svc Pri1 High priority, do before Pri2 and Pri3

Comments

@tcoakley
Copy link

tcoakley commented Jul 12, 2024

Type of issue

Code doesn't work

Description

[Enter feedback here]
The provided code is great, but it returns true for this invalid email address. me@-test.com

This regex adjustment fixes this

                return Regex.IsMatch(email,
                    @"^[^@\s]+@[^@\s-]+\.[^@\s-]+$",
                    RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));

Page URL

https://learn.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format#example

Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format.md

Document Version Independent Id

fd3699bb-4881-b6b4-1275-43eed3d5f626

Article author

@adegeo

Metadata

  • ID: 202e3f9f-a12a-53de-9069-fd469e3dbebc
  • Service: dotnet-fundamentals
@issues-automation issues-automation bot added dotnet-fundamentals/svc Pri1 High priority, do before Pri2 and Pri3 labels Jul 12, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 12, 2024
@adegeo adegeo added the doc-enhancement Improve the current content [org][type][category] label Aug 13, 2024
@adegeo
Copy link
Contributor

adegeo commented Aug 13, 2024

Hi @tcoakley

Thank you for the suggestion. At this time we're not modifying the examples here. We've had a lot of issues opened for this article suggesting various tweaks, fixes, and improvements, to the regex. It can be endlessly expanded and overcomplicated. Because of the possible endless tweaks to the regex, we don't commit time to working on the regex and instead guide the readers with this note:

It's recommended that you use the simple (@)(.+)$ regular expression pattern to normalize the domain and then return a value indicating that it passed or failed. However, the example in this article describes how to use a regular expression further to validate the email. Regardless of how you validate an email, you should always send a test email to the address to ensure it exists.

While your suggestion starts to improve the regex, it is still technically invalid. It does correctly detect the invalid domain me@-test.com, but it also flags me@domain-test.com as invalid, but that is actually a valid domain name.

@adegeo adegeo closed this as completed Aug 13, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Aug 13, 2024
@adegeo adegeo self-assigned this Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-enhancement Improve the current content [org][type][category] dotnet-fundamentals/svc Pri1 High priority, do before Pri2 and Pri3
Projects
None yet
Development

No branches or pull requests

3 participants