{"record":{"id":"2a0b16473245f2c3","repo":"Mintplex-Labs/anything-llm","slug":"username-must-start-with-a-lowercase-letter-and-on","errorCode":null,"errorMessage":"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods","messagePattern":"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/user.js","lineNumber":43,"sourceCode":"    \"dailyMessageLimit\",\n    \"bio\",\n  ],\n  validations: {\n    /**\n     * Unix-style username regex:\n     * - Must start with a lowercase letter\n     * - Can contain lowercase letters, digits, underscores, hyphens, @ signs, and periods\n     * - 2-64 characters long\n     */\n    username: (newValue = \"\") => {\n      try {\n        const username = String(newValue);\n        if (username.length > 64)\n          throw new Error(\"Username cannot be longer than 64 characters\");\n        if (username.length < 2)\n          throw new Error(\"Username must be at least 2 characters\");\n        if (!User.usernameRegex.test(username))\n          throw new Error(\n            \"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods\"\n          );\n        return username;\n      } catch (e) {\n        throw new Error(e.message);\n      }\n    },\n    role: (role = \"default\") => {\n      const VALID_ROLES = [\"default\", \"admin\", \"manager\"];\n      if (!VALID_ROLES.includes(role)) {\n        throw new Error(\n          `Invalid role. Allowed roles are: ${VALID_ROLES.join(\", \")}`\n        );\n      }\n      return String(role);\n    },\n    dailyMessageLimit: (dailyMessageLimit = null) => {\n      if (dailyMessageLimit === null) return null;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/user.js#L25-L61","documentation":"Thrown by User.validations.username when the value fails User.usernameRegex (/^[a-z][a-z0-9._@-]*$/). It must start with a lowercase letter and may contain only lowercase letters, digits, underscores, periods, hyphens, and @ signs. Note the error message omits the @ sign that the regex and the code comment both permit — a real @ in the value is actually accepted.","triggerScenarios":"Creating/updating a username that starts with an uppercase letter, a digit, a symbol, or that contains uppercase letters, spaces, or disallowed symbols (e.g. 'John', '1abc', 'ab cd', 'ab!').","commonSituations":"SSO/IdP returns an email-style or mixed-case principal that does not satisfy the Unix-style rule. User pastes a display name with capitals. Import from a system that permits uppercase.","solutions":["Lowercase the username and ensure it starts with a lowercase letter.","Strip spaces and any character outside [a-z0-9._@-].","In SSO mapping, normalize the external identifier to a compliant handle."],"exampleFix":"// before\nconst validated = User.validations.username('John Doe');\n// after\nconst handle = 'john.doe'.toLowerCase().replace(/[^a-z0-9._@-]/g, '');\nconst validated = User.validations.username(handle);","handlingStrategy":"validation","validationCode":"const USERNAME_RE = /^[a-z][a-z0-9._@-]*$/;\nfunction normalizeUsername(raw) {\n  return String(raw).toLowerCase().replace(/[^a-z0-9._@-]/g, '');\n}","typeGuard":"const isValidUsername = (u) => typeof u === 'string' && /^[a-z][a-z0-9._@-]*$/.test(u);","tryCatchPattern":null,"preventionTips":["Lowercase usernames before submission.","Strip disallowed characters client-side.","Normalize SSO principal names into compliant Unix-style handles."],"tags":["validation","user","regex","naming"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}