Free tool · runs in your browser
Username regex tester
Test username length, allowed characters and separators. Pick a generic, GitHub, Instagram or Twitter/X style preset, paste usernames one per line, and check syntax and reserved names in your browser.
3-16 ASCII letters, digits, dots, underscores or hyphens. Must start and end with a letter or digit; consecutive separators are allowed.
5 of 10 pass
| Username | Syntax | Result |
|---|---|---|
john_doe | Pass | Pass |
a | Fail | Fail |
.john | Fail | Fail |
john..doe | Pass | Pass |
admin | Pass | Reserved |
Jean-Luc | Pass | Pass |
user- | Fail | Fail |
ab12 | Pass | Pass |
ROOT | Pass | Reserved |
john__doe | Pass | Pass |
Reserved names are blocked case-insensitively, even when their syntax passes. This does not check whether an account exists.
HTML pattern is checked with the v flag in modern browsers; escape - inside character classes. Validate syntax, reserved names and uniqueness on the server.
Username rules and reserved names
The generic preset allows 3-16 ASCII letters, digits, dots, underscores and hyphens, with a letter or digit at each end. Choose no double separators to also reject adjacent punctuation. Platform-style presets use their own length and separator rules.
The tester separately blocks admin, root, support, api, www, null, undefined and system regardless of case. Regex cannot check account availability; enforce uniqueness on the server.
Recommended pattern
Default preset: ^[a-zA-Z0-9](?:[a-zA-Z0-9._-]{1,14})[a-zA-Z0-9]$. Requires 3-16 characters and a letter or digit at both ends. Reserved names are checked separately.
| Preset | Regex | Pass / fail examples | Notes |
|---|---|---|---|
| Generic (3-16 characters) | ^[a-zA-Z0-9](?:[a-zA-Z0-9._-]{1,14})[a-zA-Z0-9]$ | Pass: john_doe, Jean-Luc, ab12, john..doeFail: a, .john, user-, abcdefghijklmnopq | 3-16 ASCII letters, digits, dots, underscores or hyphens. Must start and end with a letter or digit; consecutive separators are allowed. |
| No double separators (3-16 characters) | ^(?!.*[._-]{2})[a-zA-Z0-9](?:[a-zA-Z0-9._-]{1,14})[a-zA-Z0-9]$ | Pass: john_doe, Jean-Luc, ab12Fail: john..doe, john__doe, john._doe, .john, user- | Generic rules plus a negative lookahead rejecting any two adjacent separators, including mixed pairs such as ._ or -_. |
| GitHub style (1-39 characters) | ^[a-zA-Z0-9](?:[a-zA-Z0-9]|-(?=[a-zA-Z0-9])){0,38}$ | Pass: a, Jean-Luc, ab12Fail: john_doe, john.doe, john--doe, user- | 1-39 letters or digits with single internal hyphens. No dots, underscores, leading or trailing hyphens. This tests syntax, not account availability. |
| Instagram style (1-30 characters) | ^(?!\.)(?!.*\.$)(?!.*\.\.)[a-zA-Z0-9._]{1,30}$ | Pass: a, john_doe, john.doe, _john_Fail: .john, john., john..doe, Jean-Luc | 1-30 letters, digits, dots or underscores. No leading, trailing or consecutive dots; underscores may repeat. Availability is checked separately. |
| Twitter/X style (4-15 characters) | ^[A-Za-z0-9_]{4,15}$ | Pass: john_doe, ab12, _userFail: abc, john.doe, Jean-Luc, abcdefghijklmnop | 4-15 ASCII letters, digits or underscores. No dots or hyphens. This preset checks syntax only and does not query X. |
HTML username input
<label for="username">Username</label>
<input id="username" name="username" type="text" autocomplete="username" autocapitalize="none" spellcheck="false" pattern="[a-zA-Z0-9](?:[a-zA-Z0-9._\-]{1,14})[a-zA-Z0-9]" title="3-16 letters, digits, dots, underscores or hyphens; start and end with a letter or digit" minlength="3" maxlength="16" required>Use autocomplete="username" for autofill. The pattern attribute matches the whole value with the v flag; escape literal hyphens. Pair it with required. HTML pattern checks syntax; add reserved-name checks on the server.
Validate on the server too
const USERNAME_RE = new RegExp("^[a-zA-Z0-9](?:[a-zA-Z0-9._-]{1,14})[a-zA-Z0-9]$");
const RESERVED = new Set(["admin", "root", "support", "api", "www", "null", "undefined", "system"]);
const ok = USERNAME_RE.test(value) && !RESERVED.has(value.toLowerCase());$username = $_POST['username'] ?? '';
$reserved = ['admin', 'root', 'support', 'api', 'www', 'null', 'undefined', 'system'];
$ok = is_string($username)
&& preg_match('/\A[a-zA-Z0-9][a-zA-Z0-9._-]{1,14}[a-zA-Z0-9]\z/', $username) === 1
&& !in_array(strtolower($username), $reserved, true);import re
USERNAME_RE = re.compile(r"[a-zA-Z0-9][a-zA-Z0-9._-]{1,14}[a-zA-Z0-9]")
RESERVED = {"admin", "root", "support", "api", "www", "null", "undefined", "system"}
ok = USERNAME_RE.fullmatch(username) is not None and username.lower() not in RESERVEDThese examples use the generic preset plus reserved-name checks. Use full-string matching and enforce a unique database constraint for account creation.
Username regex FAQ
What is a good regex for usernames?
For a 3-16 character ASCII username, use ^[a-zA-Z0-9](?:[a-zA-Z0-9._-]{1,14})[a-zA-Z0-9]$. It allows letters, digits, dots, underscores and hyphens, but requires a letter or digit at both ends. Check reserved names and uniqueness separately.
How do I stop consecutive dots or underscores?
Choose the no double separators preset. Its (?!.*[._-]{2}) lookahead rejects consecutive dots, underscores or hyphens, including mixed pairs. The generic preset permits consecutive separators.
Why does my pattern attribute with a hyphen fail?
Modern browsers compile HTML pattern with the v flag. Escape a literal hyphen as \- inside character classes; an invalid pattern can cause the browser to ignore the constraint. The HTML snippets here escape hyphens and omit anchors because pattern matches the entire value.
Should usernames be case-insensitive?
Choose one policy and enforce it consistently. These presets accept both uppercase and lowercase letters, and the reserved-name check is case-insensitive. If accounts are case-insensitive, normalize the lookup key on the server and enforce a unique database constraint while preserving display casing if desired.
Does a valid username mean it is available?
No. Regex checks syntax only. This tool separately blocks admin, root, support, api, www, null, undefined and system. Platform-style presets do not contact GitHub, Instagram or X, and do not guarantee account availability or acceptance.
Do I need to validate usernames on the server?
Yes. Browser validation can be bypassed. Repeat syntax, length and reserved-name checks on the server, then enforce uniqueness in the database. Use full-string matching, and decide explicitly whether to reject or trim surrounding whitespace.
Regex patterns for form fields
Alphanumeric regex tester
Test letters and numbers, spaces, handles and Unicode patterns.
Email regex tester
Test email patterns against edge cases and your own list.
Phone number regex tester
Check numbers against E.164, US/Canada and digits-only patterns.
Password regex generator
Pick strength rules and copy the regex or HTML pattern.
ZIP code regex
US ZIP, ZIP+4, Canadian and UK postal code patterns.
Number regex tester
Test digits, decimals, money and thousands separators.
Date regex tester
Date formats, strict ranges and leap-year aware ISO patterns.
Name regex tester
Validate names with accents, hyphens and apostrophes.
IP address regex tester
Validate IPv4, IPv6 and CIDR input with strict octets.
URL regex tester
Check website fields with regex, type=url or new URL().
HTML pattern attribute
How browsers anchor and check a pattern on an input.
HTML required attribute
Stop a form from sending while a field is empty.
Validate a form with JavaScript
Use checkValidity, custom messages and your own rules.
Time regex tester
Validate 24-hour, AM/PM and ISO 8601 time formats.
Credit card regex tester
Match card brands by prefix and length, then run a Luhn check.
Hex color regex tester
Match hex, rgb() and hsl() colors with range checks and swatches.
UUID regex tester
Match UUID v4, v7 and GUIDs with version and variant checks.
Use your validation patterns as you assemble a form with our HTML contact form code or HTML form generator.
More free form tools
Form backend cost calculator
Enter monthly submissions and compare the cheapest listed plan across eight form backends.
Email deliverability checker
Enter a domain to check its SPF, DMARC and MX records and get a plain-English fix for each.
SPF record checker
Look up a domain's SPF record, see each mechanism explained and count DNS lookups against the 10-lookup limit.
DMARC record generator
Pick a policy and report address and copy a ready _dmarc TXT record.
DMARC checker
Look up a domain's DMARC record and see the policy and every tag explained.
DKIM record checker
Enter a domain and selector to check its DKIM key, with presets for common senders.
SPF record generator
Tick your email providers and copy one SPF TXT record with a lookup count.
Contact form spam checker
Paste form HTML to audit its honeypot, endpoint, CAPTCHA markers and spam resistance.
Honeypot field generator
Generate a hidden anti-spam input with your chosen name and hiding technique.
Form action URL tester
Check a form action URL for reachability, CORS headers, POST acceptance and backend.
Email obfuscator
Encode your email so spam scrapers can't read it but people can still click it.
Mailto link generator
Build a mailto: URL with recipients, CC, BCC, subject and a pre-filled body.
HMAC-SHA256 generator
Generate and verify webhook signatures for common providers in your browser.
URL encoder and decoder
Encode text, build an x-www-form-urlencoded body or parse a query string.
UTM builder
Build campaign URLs with UTM parameters, tag a CSV in bulk and check tagged links.
HTML to JSX converter
Paste HTML and get JSX or a working React/Next.js form component.
Image to Base64 converter
Convert images to Base64 data URLs in your browser and copy HTML and CSS snippets.
Base64 to image converter
Paste a Base64 data URI to preview and download the decoded image.
Base64 decode & encode
Decode Base64 to readable UTF-8 text or encode text to Base64, locally in your browser.
URL to Base64 converter
Fetch a direct image URL in your browser and get its Base64 data URL.
AI form generator
Describe your form in plain English and copy working HTML.