Skip to content

Email validation rejects valid addresses with hyphenated domain labels #360

Open

Description

@noshita

Prerequisites

Description

git add-coauthor rejects valid email addresses whose domain labels contain hyphens (e.g., kyushu-u.ac.jp, example-corp.com) with the error Invalid email format..
Hyphens in domain labels are allowed by RFC 1035 2.3.1, so these addresses should be accepted.

Steps to Reproduce

  1. Run git add-coauthor tu "Test User" user@kyushu-u.ac.jp
  2. Observe the error message

Expected behavior: The coauthor with the hyphenated domain email is added to .git-coauthors.

Actual behavior: The command fails with Invalid email format. and nothing is written to .git-coauthors.

Reproduces how often: 100%

Versions

  • operating system and version: macOS Tahoe 26.4
  • git-mob version (git-mob --version): 4.0.1
  • git version (git --version): 2.53.0

Additional Information

The validateEmail function in packages/git-mob/src/helpers.ts uses the regex (\w+\.)+[a-zA-Z]{2,} for the domain portion of an email address.
JavaScript's \w is [A-Za-z0-9_] and does not include -, so this pattern fails to match any label that contains a hyphen.

I work around this by registering with a dummy address (e.g., xxx@gmail.com) and then manually editing .git-coauthors (path: git mob -p) to replace it with the actual address.

Suggested fix (accepts - and rejects _ in the domain part, since _ is not valid in DNS labels per RFC 1035):

- /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}])|((\w+\.)+[a-zA-Z]{2,}))$/
+ /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[(?:\d{1,3}\.){3}\d{1,3}])|(([A-Za-z0-9-]+\.)+[A-Za-z]{2,}))$/

Activity

  1. rkotze commented on Apr 10, 2026

    @rkotze
    Owner

    @noshita thanks for raising the issue and investigating where the problem is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions