Fix username validation: strip invalid chars instead of pattern error
Browser's native pattern validation fired before preventDefault, showing "The string did not match the expected pattern" error. Replace HTML pattern with onChange that strips invalid characters. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2215099501
commit
6950fd7de5
1 changed files with 1 additions and 2 deletions
|
|
@ -87,9 +87,8 @@ export default function RegisterPage() {
|
|||
id="username"
|
||||
type="text"
|
||||
required
|
||||
pattern="[a-z0-9_-]+"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value.toLowerCase())}
|
||||
onChange={(e) => setUsername(e.target.value.toLowerCase().replace(/[^a-z0-9_-]/g, ""))}
|
||||
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||
placeholder="alice"
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue