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_doeMatches
john_doe
Input
user-123Matches
user-123
Input
abNo match
—Common use cases
- •User registration form validation
- •API username parameter sanitization
- •Social platform handle creation
- •Database username format enforcement
Related patterns
Alphanumeric Only
ValidationMatch strings containing only letters (A–Z, a–z) and digits (0–9), with no spaces or special characters.
Twitter / X Handle
ValidationMatch Twitter/X @handles — 1 to 15 characters of letters, digits, or underscores preceded by @.
Password (No Special Chars)
ValidationValidate passwords requiring at least one lowercase, one uppercase, one digit, and minimum 8 characters — no special characters required.
IBAN (International Bank Account Number)
ValidationValidate IBAN bank account identifiers: 2-letter country code, 2 check digits, 11–30 alphanumerics.