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

Open
wants to merge 3 commits into
base: main
Choose a base branch
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

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
1 participant