Skip to main content
CalcHive

Regex for Username

Matches usernames: 3-30 characters, starts with a letter, allows letters, digits, dots, underscores, and hyphens.

Pattern

/^[a-zA-Z][a-zA-Z0-9._-]{2,29}$/

Pattern Breakdown

TokenExplanation
^Start of string
[a-zA-Z]Must start with a letter
[a-zA-Z0-9._-]{2,29}2-29 more characters (letters, digits, dot, underscore, hyphen)
$End of string

Test Examples

InputMatch?
john_doeMatch
user123Match
a.b-cMatch
1userNo match
abNo match

Common Use Cases

  • User registration validation
  • Profile URL slugs
  • Social media handles

Variations

^[a-zA-Z0-9_]{3,20}$

Alphanumeric and underscore only

Want to test this pattern with your own data?

Open the Regex Tester