Skip to content

Improve Email Validation Regex for Better Input Sanitization #3

@RajivBB

Description

@RajivBB

Description

While reviewing input validation logic, I noticed the current regex used for email validation is overly permissive and can lead to accepting invalid email formats.

Current regex:

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

Identified Issues

This regex:

  • Matches many common emails, but...
  • Also matches invalid formats, such as:
john..doe@example.com (consecutive dots)
.john@example.com (starts with dot)
john.@example.com (ends with dot)
john@-example.com (hyphen at start of domain)
john@example-.com (hyphen at end of domain)

These can cause downstream issues in email-related systems or user account processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions