Social
TikTok username Regex
TikTok usernames are 2 to 24 characters long and may contain letters, digits, underscores and dots, but they cannot end with a dot. This pattern checks that shape with an optional leading @, so it works whether people paste @test.user or just test.user. It suits creator onboarding forms, campaign spreadsheets and influencer outreach tools that collect handles from many sources. The pattern does not block consecutive dots, which TikTok may also reject in some cases, and it obviously cannot confirm that a profile with that name exists or is public.
Pattern (JavaScript)
/^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$/Starts at the start of the line/string, then the character "@", optionally (zero or one time), then one of the characters A-Za-z0-9_, then one of the characters A-Za-z0-9_., between 0 and 22 times, then one of the characters A-Za-z0-9_, then the end of the line/string.
Examples
Matches
- ✓ @test.user
- ✓ test_user_01
- ✓ @ab
- ✓ sample.creator_2026
Does not match
- ✗ @test.
- ✗ @a
- ✗ @test-user
- ✗ @abcdefghijklmnopqrstuvwxy
Try it
0 matches (JavaScript engine)
@test.user
test_user_01
@ab
sample.creator_2026
@test.
@a
@test-user
@abcdefghijklmnopqrstuvwxyCode in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$/g;
const text = "@test.user";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$')
text = '@test.user'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$/';
$text = '@test.user';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$");
String text = "@test.user";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$`)
text := "@test.user"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$");
var text = "@test.user";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$").unwrap();
let text = "@test.user";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^@?[A-Za-z0-9_][A-Za-z0-9_.]{0,22}[A-Za-z0-9_]$/
text = '@test.user'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why can't a TikTok username end with a dot?
- TikTok disallows a trailing dot to avoid confusion with URLs and sentence punctuation. The pattern enforces this by requiring the last character to be a letter, digit or underscore.
- Is the @ part of the username?
- No. The @ is just how handles are displayed. The pattern makes it optional so input with or without it passes, but strip it before storing the name.
- Are uppercase letters allowed?
- TikTok stores usernames in lowercase, but users often type capitals. The pattern accepts both; convert to lowercase before saving or comparing to avoid duplicates.