Regex for username

/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/gm

Options
Matches

Examples

Note

Starts with a letter, then 3–16 characters in total of letters, digits and underscores. Adjust the {2,15} for other lengths.

Matches in the example

  • "ana_92"
  • "Bob"

Token by token

  1. ^ the start of the string (or line, with the m flag)
  2. [a-zA-Z] one of: “a” to “z” or “A” to “Z”
  3. [a-zA-Z0-9_]{2,15} one of: “a” to “z”, “A” to “Z”, “0” to “9” or “_”, between 2 and 15 times, as many as possible
  4. $ the end of the string (or line, with the m flag)

Other patterns