Authentication & Security · In-Browser Regular Expression Lab
Username Regex — 3 to 20 Characters with Letters, Digits & Underscores
Standard web application username policy: 3 to 20 characters, starting with a letter, allowing underscores.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:alex_dev
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
alex_dev Pass
sarah99 Pass
CastovUser Pass
Expected Invalid Samples (Must Reject)
9alex Rejected (Pass)
_user Rejected (Pass)
us Rejected (Pass)
this_username_is_way_too_long_for_policy Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^[a-zA-Z][a-zA-Z0-9_]{2,19}$/;
const text = "alex_dev";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Begins with an ASCII letter, followed by 2 to 19 alphanumeric characters or underscores. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| ^[a-zA-Z] | First Letter | Must start with a letter (no leading numbers or underscores). |
| [a-zA-Z0-9_]{2,19}$ | Trailing Chars | 2 to 19 characters total length 3-20. |
Frequently Asked Questions
How to allow hyphens?
Related Regular Expressions
Browse All 40 PatternsAuthentication & Security
Email Address Validation
Standard, robust regular expression to validate email addresses including alphanumeric characters, dots, plus signs, and modern TLDs.
/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/Test regex
Authentication & Security
Strong Password Policy
Enforces minimum 8 characters, at least one uppercase letter, one lowercase letter, one digit, and one special character.
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#])[A-Za-z\d@$!%*?&#]{8,}$/Test regex
Data & Formatting
URL Slug Matcher
Matches lowercase alphanumeric strings separated by single hyphens, ideal for SEO permalinks.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Test regex