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:
Ullrich Schäfer 2026-03-23 21:51:34 +01:00
parent 2215099501
commit 6950fd7de5
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -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"
/>