Launching a SaaS?·Collect waitlist signups before you build — before.run
SandboxPatternsDetectDocsChangelog
Social
#username
#user
#handle
#login

Username

Matches a valid username: 3–20 characters, letters, digits, hyphens, and underscores. No leading/trailing hyphens or underscores.

✓ User registration✓ Social media handles✓ API key naming
/
/
Safe
Test String
No matches
^^— ^ — start of string (or line in multiline mode)
[…]Character class […]— Matches any single character listed in this set
a-za-z— a-z — range from 'a' to 'z'
A-ZA-Z— A-Z — range from 'A' to 'Z'
0-90-9— 0-9 — range from '0' to '9'
(?!…)Negative lookahead (?!…)— Negative lookahead — asserts the following text does NOT match this pattern (zero-width)
.*.— . — matches any character except newline (unless 's' flag is set) — repeated zero or more times (greedy) · * — zero or more times (greedy)
[…]{2}Character class […]— Matches any single character listed in this set — repeated exactly 2 times · {2} — exactly 2 times
[…]{1,18}Character class […]— Matches any single character listed in this set — repeated between 1 and 18 times · {1,18} — between 1 and 18 times
a-za-z— a-z — range from 'a' to 'z'
A-ZA-Z— A-Z — range from 'A' to 'Z'
0-90-9— 0-9 — range from '0' to '9'
__— '_' — literal character
\-\-— \- — escaped character
[…]Character class […]— Matches any single character listed in this set
a-za-z— a-z — range from 'a' to 'z'
A-ZA-Z— A-Z — range from 'A' to 'Z'
0-90-9— 0-9 — range from '0' to '9'
$$— $ — end of string (or line in multiline mode)
Pattern: 57 charsInput: 34 chars
100% client-side · private

✓ Valid Examples

  • john_doe
  • user-123
  • alice
  • web_dev_42

✗ Invalid Examples

  • -john
  • john-
  • _user
  • a
  • this_username_is_way_too_long_for_any_system

Usage & Integration

Validate Username natively in your backend or frontend without copying regex strings.

Node / Edge

import { validate } from '@regexto/validators';

validate('username', '...');

Python

from regexto_validators import validate

validate("username", "...")

Go

import "github.com/regex-to/validators-go"

valid, err := validators.Validate("username", "...")

PHP

use RegexTo\Validators\Validator;

Validator::validate('username', '...');

Rust

use regexto_validators::validate;

let is_valid = validate("username", "...").unwrap();