100% Client-Side β’ 0 B Data Leaves Browser
web
Twitter / X Username Handle Regex
Validates Twitter and X user handles, allowing an optional leading @ symbol and up to 15 alphanumeric or underscore characters.
Regular Expression Pattern:
/^@?[a-zA-Z0-9_]{1,15}$/
Valid Match Example:
@devtransform
Invalid / Non-Match Example:
@this_username_is_way_too_long_for_x
Regex Syntax Breakdown & Explanation
- β’^@? : Optional leading @ symbol
- β’[a-zA-Z0-9_]{1,15}$ : Restricts handle length to Twitter policy max of 15 chars
Implementation in Popular Languages
JavaScript / TypeScript
const regex = /^@?[a-zA-Z0-9_]{1,15}$/;
const isValid = regex.test("@devtransform");
console.log(isValid); // truePython (re)
import re
pattern = r"^@?[a-zA-Z0-9_]{1,15}$"
match = re.match(pattern, "@devtransform")
print(bool(match)) # TrueGo (regexp)
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^@?[a-zA-Z0-9_]{1,15}$`)
fmt.Println(re.MatchString("@devtransform"))
}Frequently Asked Questions
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
The regular expression pattern is /^@?[a-zA-Z0-9_]{1,15}$/. Validates Twitter and X user handles, allowing an optional leading @ symbol and up to 15 alphanumeric or underscore characters.