Validation

Username

Validate usernames that are 3–16 characters long and contain only letters, digits, underscores, and hyphens.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
^[a-zA-Z0-9_\-]{3,16}$

Raw source: ^[a-zA-Z0-9_\-]{3,16}$

How it works

^ and $ anchor to the full string. The character class [a-zA-Z0-9_\-] allows letters (upper and lower), digits, underscores, and hyphens. {3,16} enforces the length range most platforms use for usernames.

Examples

Input

john_doe

Matches

  • john_doe

Input

user-123

Matches

  • user-123

Input

ab

No match

Common use cases

  • User registration form validation
  • API username parameter sanitization
  • Social platform handle creation
  • Database username format enforcement