Visual regex workbench

Build, import, explain, test and share regex visually.

Regex guide

Username Regex Examples

Username validation is a common regex use case for login forms, profiles, admin panels, games and community platforms. This guide provides practical username regex examples you can test and adapt.

Letters and numbers

Allows only ASCII letters and digits.

Suggested pattern

^[A-Za-z0-9]+$
Quick test

What it matches

  • Franck2026
  • User123

Common limitations

  • No underscores or hyphens.
  • ASCII only.

Letters, numbers and underscore

Allows common username characters.

Suggested pattern

^[A-Za-z0-9_]+$
Quick test

What it matches

  • john_doe
  • user_123

Common limitations

  • No hyphens.
  • No length limit.

Username with length limit

Allows letters, numbers and underscores from 3 to 20 characters.

Suggested pattern

^[A-Za-z0-9_]{3,20}$
Quick test

What it matches

  • john_doe
  • user_123

Common limitations

  • ASCII only.
  • Does not allow hyphens.

Lowercase username

Allows lowercase letters, numbers and underscores only.

Suggested pattern

^[a-z0-9_]{3,20}$
Quick test

What it matches

  • john_doe
  • user_123

Common limitations

  • Uppercase letters are rejected.
  • ASCII only.

Username with hyphen

Allows letters, numbers, underscores and hyphens.

Suggested pattern

^[A-Za-z0-9_-]{3,20}$
Quick test

What it matches

  • john-doe
  • user_123

Common limitations

  • Allows hyphens at the beginning or end.
  • ASCII only.

International username

Allows Unicode letters, numbers and underscores.

Suggested pattern

^[\p{L}\p{N}_]{3,20}$
Quick test

What it matches

  • françois
  • 用户123

Common limitations

  • Requires Unicode property escape support.
  • In JavaScript, the u flag is required.

What is a username regex?

A username regex is a pattern used to check whether a username follows the rules of a website, app, game or internal system.

It can define allowed characters, minimum length, maximum length, case sensitivity and whether symbols such as underscores or hyphens are accepted.

Common username validation rules

Most username rules allow letters and numbers, then optionally add underscores, hyphens or dots.

A common approach is to require between 3 and 20 characters, reject spaces and keep the username easy to display in URLs and profiles.

ASCII usernames vs Unicode usernames

ASCII username regex patterns are simpler and work well for English-only systems.

Unicode username patterns are better for international websites because they can allow accented letters and non-Latin scripts, but they require Unicode-aware regex support.

What regex cannot validate

A regex can check the format of a username, but it cannot know whether the username is already taken.

Availability checks, reserved names, banned words and account rules should still be handled by server-side validation.