Hyphen needs to be escaped to "\-", and alphanumeric can be simplified to "\w".
} while (await env.links.get(shortUrl) !== null); // Confirm it's not already taken
}
// Invalid short URLs
- else if (!/^[0-9a-zA-Z-_]*$/g.test(shortUrl) || shortUrl === 'api') {
+ else if (!/^[\w\-]+$/g.test(shortUrl) || shortUrl === 'api') {
return new Response('Invalid short URL.', { status: 400, headers: { 'Content-Type': 'text/plain; charset=UTF-8' } });
}
// User-provided duplicates
<label for="short-url">Custom short path</label>
<aside id="short-url-aside">Connect wallet to enable this feature.</aside>
<!-- Maximum 80 characters, valid characters are alphanumeric, hyphen (-), and underscore (_) -->
- <input type="text" id="short-url" name="short-url" placeholder="example" maxlength="80" pattern="^[0-9a-zA-Z-_]*$" disabled>
+ <input type="text" id="short-url" name="short-url" placeholder="example" maxlength="80" pattern="[\w\-]+" disabled>
</div>
<button type="submit" id="generate" class="text-button">Create short link</button>