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
| Token | Explanation |
|---|---|
| ^ | 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
| Input | Match? |
|---|---|
| john_doe | Match |
| user123 | Match |
| a.b-c | Match |
| 1user | No match |
| ab | No match |
Common Use Cases
- User registration validation
- Profile URL slugs
- Social media handles
Variations
^[a-zA-Z0-9_]{3,20}$Alphanumeric and underscore only
Other Regex Patterns
Want to test this pattern with your own data?
Open the Regex Tester