splitforms.com

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

UsernameSyntaxResult
john_doePassPass
aFailFail
.johnFailFail
john..doePassPass
adminPassReserved
Jean-LucPassPass
user-FailFail
ab12PassPass
ROOTPassReserved
john__doePassPass

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.

PresetRegexPass / fail examplesNotes
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..doe
Fail: 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, ab12
Fail: 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, ab12
Fail: 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, _user
Fail: 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

username.html

<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

validate-username.js

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());
validate-username.php

$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);
validate-username.py

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 RESERVED

These 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.

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.

See all free tools