Skip to content

[Bug] Frontend username validation in Signup.tsx rejects valid usernames containing numbers and underscores #413

@anshul23102

Description

@anshul23102

Description

The frontend signup form in src/pages/Signup/Signup.tsx applies a username validation regex that only permits letters and spaces:

if (!/^[A-Za-z\s]+$/.test(value)) {
  errorMessage = "Only letters are allowed";
}

However, the backend validator in backend/validators/authValidator.js accepts usernames containing letters, numbers, and underscores:

username: z.string()
  .regex(/^[a-zA-Z0-9_]+$/, "Username can only contain letters, numbers, and underscores")

These two rulesets directly contradict each other.

Impact

A user entering a username such as john_doe or john123 is blocked by the frontend with the message "Only letters are allowed", even though the backend would accept it. Users with common username patterns cannot register at all. The frontend also accepts spaces (e.g. john doe) that the backend rejects, producing a confusing server-side validation error after submission.

Steps to Reproduce

  1. Navigate to the Sign Up page.
  2. Enter a username containing a digit or underscore, e.g. dev_user1.
  3. Observe the inline error: "Only letters are allowed".
  4. The form cannot be submitted despite the username being valid per the backend rules.

Expected Behavior

The frontend should permit the same character set as the backend: letters, digits, and underscores, with a consistent error message.

Proposed Fix

Update the username validation regex in src/pages/Signup/Signup.tsx to match the backend rule:

// Before
if (!/^[A-Za-z\s]+$/.test(value)) {
  errorMessage = "Only letters are allowed";
}

// After
if (!/^[a-zA-Z0-9_]+$/.test(value)) {
  errorMessage = "Username can only contain letters, numbers, and underscores";
}

Apply the same correction in the handleSubmit validation block in the same file.

Affected Files

  • src/pages/Signup/Signup.tsx
  • backend/validators/authValidator.js (source of truth for the accepted format)

Suggested Labels

type:bug level:intermediate quality:exceptional

I would like to work on this issue under GSSoC 2026. Could you please assign it to me? @GitMetricsLab

/assign

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions