Skip to content

fix(profile): improve full name validation with clearer error messages#1396

Open
rohilsurana wants to merge 4 commits intomainfrom
fix/user-profile-name-validation
Open

fix(profile): improve full name validation with clearer error messages#1396
rohilsurana wants to merge 4 commits intomainfrom
fix/user-profile-name-validation

Conversation

@rohilsurana
Copy link
Member

Summary

  • Improved full name validation in user profile to allow only letters, spaces, periods, hyphens, and apostrophes
  • Ensured special characters (spaces, hyphens, apostrophes) can only appear after at least one letter
  • Added multiple validation rules with clear, specific error messages for better UX

Changes

  • Reordered validation checks to show most relevant error message first
  • Name must start and end with a letter
  • Special characters must be followed by a letter
  • No consecutive spaces allowed

Test plan

  • Test with valid names: "John Doe", "Mary-Jane O'Connor", "Dr. Smith"
  • Test invalid: trailing space shows "Name must end with a letter"
  • Test invalid: trailing hyphen shows "Name must end with a letter"
  • Test invalid: trailing apostrophe shows "Name must end with a letter"
  • Test invalid: numbers/symbols show "Name can only contain..."
  • Test invalid: space not followed by letter shows "Spaces must be followed by a letter"

@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Feb 19, 2026 6:50am

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened name-field validation: names must start and end with a letter and cannot contain consecutive spaces.
    • Enforced that spaces, hyphens, and apostrophes must be followed by a letter to prevent invalid sequences.
    • Expanded allowed characters to include periods and added clear, per-rule error messages guiding correct name entry.
    • No changes to avatar, email, or submission behavior.

Walkthrough

Name validation in the user update form was refactored into multiple constraints: names must start and end with a letter, allow Unicode letters and periods, disallow consecutive spaces, and require spaces/hyphens/apostrophes to be followed by a letter; per-constraint messages were added.

Changes

Cohort / File(s) Summary
Name Validation Enhancement
web/lib/react/components/organization/user/update.tsx
Replaced single-name regex with multiple chained validation constraints: require start/end with a letter, allow Unicode letters and periods, prevent consecutive spaces, and require that spaces, hyphens, and apostrophes are followed by a letter. Added distinct error messages for each rule.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coveralls
Copy link

coveralls commented Feb 18, 2026

Pull Request Test Coverage Report for Build 22171604098

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 171 unchanged lines in 12 files lost coverage.
  • Overall coverage increased (+0.1%) to 38.457%

Files with Coverage Reduction New Missed Lines %
cmd/namespace.go 4 64.86%
cmd/context.go 7 0.0%
cmd/client.go 8 64.86%
cmd/preferences.go 8 49.36%
cmd/user.go 10 43.81%
cmd/policy.go 12 55.56%
cmd/permission.go 13 54.55%
cmd/role.go 14 51.53%
cmd/project.go 15 52.4%
cmd/organization.go 16 48.71%
Totals Coverage Status
Change from base Build 22136300698: 0.1%
Covered Lines: 16200
Relevant Lines: 42125

💛 - Coveralls

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/lib/react/components/organization/user/update.tsx (1)

35-38: Simplify the "end with letter" regex — the single-char alternative |^[a-zA-Z]$ is unreachable dead code.

.min(2) is enforced before this .matches(), so a single-character string never reaches it. The entire two-alternative regex can be reduced to a simpler end-anchor check (the start constraint is already covered by the preceding rule):

♻️ Proposed simplification
-      .matches(
-        /^[a-zA-Z][a-zA-Z\s.'\-]*[a-zA-Z]$|^[a-zA-Z]$/,
-        'Name must end with a letter'
-      )
+      .matches(
+        /[a-zA-Z]$/,
+        'Name must end with a letter'
+      )

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment on lines 28 to 42
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Period validation gap — consecutive periods (e.g., "John..Doe") pass all checks.

The PR description states that periods, like spaces/hyphens/apostrophes, must be followed by a letter, but no .matches() constraint enforces this for periods. As a result:

  • "John..Doe" — two consecutive periods — is accepted as valid.
  • "Dr..Smith" — same issue.

Note: "Dr. Smith" (period → space → letter) is correctly valid per the current code because the existing space-follow check handles the space after the period. However, any period followed directly by another non-letter special character (e.g., another period) slips through.

If the intent is to match the stated requirement, add:

🛡️ Proposed fix to enforce letter-after-period
       .matches(
         /^(?!.*'[^\p{L}]).*$/u,
         'Apostrophes must be followed by a letter'
-      ),
+      )
+      .matches(
+        /^(?!.*\.[^\p{L}\s]).*$/u,
+        'Periods must be followed by a letter or space'
+      ),

If the stricter rule (period must be followed only by a letter, not a space) is desired — which would invalidate "Dr. Smith" — use /^(?!.*\.[^\p{L}]).*$/u instead. Confirm the intended behaviour against the listed valid test cases before applying.

🧰 Tools
🪛 GitHub Check: JS SDK Lint

[failure] 33-33:
Unnecessary escape character: -


[failure] 28-28:
Unnecessary escape character: -

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Comment on lines +28 to +37
/^[\p{L}\s.'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

\s permits tabs, newlines, and other whitespace — use a literal space instead.

\s matches \t, \n, \r, \f, \v, and (with the u flag) additional Unicode whitespace characters. A value like "John\tDoe" would pass every check in this chain. The error messages and PR description consistently refer to "spaces," so the intent is clearly to allow only the ASCII space character.

🔧 Proposed fix — replace \s with literal space in all four regexes
      .matches(
-        /^[\p{L}\s.'-]+$/u,
+        /^[\p{L} .'-]+$/u,
         'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
       )
       .matches(/^\p{L}/u, 'Name must start with a letter')
       .matches(
-        /^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
+        /^\p{L}[\p{L} .'-]*\p{L}$|^\p{L}$/u,
         'Name must end with a letter'
       )
-      .matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
-      .matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
+      .matches(/^(?!.*  ).*$/, 'Name cannot have consecutive spaces')
+      .matches(/^(?!.* [^\p{L}]).*$/u, 'Spaces must be followed by a letter')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/^[\p{L}\s.'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L}\s.'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.*\s\s).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.*\s[^\p{L}]).*$/u, 'Spaces must be followed by a letter')
/^[\p{L} .'-]+$/u,
'Name can only contain letters, spaces, periods, hyphens, and apostrophes'
)
.matches(/^\p{L}/u, 'Name must start with a letter')
.matches(
/^\p{L}[\p{L} .'-]*\p{L}$|^\p{L}$/u,
'Name must end with a letter'
)
.matches(/^(?!.* ).*$/, 'Name cannot have consecutive spaces')
.matches(/^(?!.* [^\p{L}]).*$/u, 'Spaces must be followed by a letter')

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments