Valid Username Regular Expression

  • + 0 comments

    public static final String regularExpression = "^[A-Za-z][A-Za-z0-9_]{7,29}$";`

    "^[A-Za-z]" → first char must be a letter.

    "[A-Za-z0-9_]{7,29}" → remaining chars must be alphanumeric or _, length between 7 and 29.

    Total length = 1 (first char) + [7–29] = 8–30 characters.

    Anchors ^...$ ensure no extra characters sneak in.