Skip to content

docs: fix #47146 – improve email validation regex to prevent invalid formats #47285

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

Closed
wants to merge 3 commits into from

Conversation

Gurry-12
Copy link
Contributor

@Gurry-12 Gurry-12 commented Jul 10, 2025

What this PR does:

This PR updates the email validation regex in the How to verify that strings are in valid email format article to address an issue where invalid characters (like commas) were being accepted.
Problem:

The current regex pattern:

^[^@\s]+@[^@\s]+.[^@\s]+$

allows email addresses like surname123@gmail.,com, which are structurally invalid.
Fix:

Replaced the regex pattern and its explanation with a more accurate expression:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$

This change:

Restricts characters in the local and domain parts to common valid characters.

Ensures the TLD has at least two alphabetical characters.

Still remains readable and practical for general validation.

Related issue:

Fixes #47146


Internal previews

📄 File 🔗 Preview link
docs/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format.md How to verify that strings are in valid email format

@Gurry-12 Gurry-12 requested review from adegeo and a team as code owners July 10, 2025 17:58
@dotnetrepoman dotnetrepoman bot added this to the July 2025 milestone Jul 10, 2025
@dotnet-policy-service dotnet-policy-service bot added dotnet-fundamentals/svc community-contribution Indicates PR is created by someone from the .NET community. labels Jul 10, 2025
@Gurry-12
Copy link
Contributor Author

@dotnet-policy-service agree

@Gurry-12 Gurry-12 marked this pull request as draft July 13, 2025 12:56
@adegeo
Copy link
Contributor

adegeo commented Jul 14, 2025

Hello, thank you for this pull request, but we're not looking to improve this page with more complex examples. The article states this, which is a policy we're following:

If you try to create the perfect regular expression to validate that the structure of an email is correct, the expression becomes so complex that it's incredibly difficult to debug or improve. Regular expressions can't validate an email exists, even if it's structured correctly. The best way to validate an email is to send a test email to the address.

@adegeo adegeo closed this Jul 14, 2025
@Gurry-12
Copy link
Contributor Author

thank you for your revert @adegeo sir, It will really help me to improve my understanding towards the contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid E-Mails will get marked as valid
2 participants