{"record":{"id":"1ce5ce4a1ac71104","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-custom-field-value-1ce5ce","errorCode":"error-invalid-custom-field-value","errorMessage":"error-invalid-custom-field-value","messagePattern":"error-invalid-custom-field-value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/guests.ts","lineNumber":57,"sourceCode":"\t\t...(name && { name }),\n\t\t...(email && { email }),\n\t\t...(phone && { phone }),\n\t\tlivechatData: {},\n\t};\n\n\tconst customFields: Record<string, any> = {};\n\n\tif ((!userId || (await hasPermissionAsync(userId, 'edit-livechat-room-customfields'))) && Object.keys(livechatData).length) {\n\t\tlivechatLogger.debug({ msg: 'Saving custom fields for visitor', visitorId: _id, livechatData });\n\t\tfor await (const field of LivechatCustomField.findByScope('visitor')) {\n\t\t\tif (!livechatData.hasOwnProperty(field._id)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst value = trim(livechatData[field._id]);\n\t\t\tif (value !== '' && field.regexp !== undefined && field.regexp !== '') {\n\t\t\t\tconst regexp = new RegExp(field.regexp);\n\t\t\t\tif (!regexp.test(value)) {\n\t\t\t\t\tthrow new Error(i18n.t('error-invalid-custom-field-value'));\n\t\t\t\t}\n\t\t\t}\n\t\t\tcustomFields[field._id] = value;\n\t\t}\n\t\tupdateData.livechatData = customFields;\n\t\tlivechatLogger.debug({\n\t\t\tmsg: 'About to update custom fields for visitor',\n\t\t\tvisitorId: _id,\n\t\t\tcustomFieldCount: Object.keys(customFields).length,\n\t\t});\n\t}\n\tconst ret = await LivechatVisitors.saveGuestById(_id, updateData);\n\n\tsetImmediate(() => {\n\t\tvoid Apps.self?.triggerEvent(AppEvents.IPostLivechatGuestSaved, _id);\n\t});\n\n\treturn ret;","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/guests.ts#L39-L75","documentation":"Thrown by `saveGuest` while processing visitor custom fields: for each `LivechatCustomField` with scope 'visitor' present in `livechatData`, a non-empty value must match the field's stored `regexp`. The message is passed through `i18n.t('error-invalid-custom-field-value')`, so the user-visible text is translation-dependent while the code stays stable.","triggerScenarios":"Submitting visitor livechatData whose value fails the admin-configured regex — e.g. a 'Phone' field with regexp `^\\+?[0-9]+$` receiving 'abc', or a field whose regexp was tightened after visitors already had free-text values saved.","commonSituations":"Regexes configured after data existed, breaking edits of old records; copy-pasted values with whitespace/emoji failing strict patterns; localized keyboards producing lookalike digits.","solutions":["Correct the submitted value so it matches the field's configured regexp (visible in Administration > Omnichannel > Custom Fields)","If existing legitimate data now fails, relax or fix the custom field's regexp in admin","Pre-validate each livechatData entry client-side against the field's regexp before calling saveGuest"],"exampleFix":"// before\nawait saveGuest({ _id, name, livechatData: { phone: 'call me' } }, userId);\n\n// after\nconst phoneRe = new RegExp(field.regexp);\nif (!phoneRe.test('call me')) {\n  throw new Error(`phone must match ${field.regexp}`);\n}\nawait saveGuest({ _id, name, livechatData: { phone: '+5511999999999' } }, userId);","handlingStrategy":"validation","validationCode":"const fields = await LivechatCustomField.findByScope('visitor').toArray();\nfor (const [key, raw] of Object.entries(livechatData)) {\n  const field = fields.find((f) => f._id === key);\n  const value = String(raw).trim();\n  if (value && field?.regexp && !new RegExp(field.regexp).test(value)) {\n    throw new Error(`${key} must match ${field.regexp}`);\n  }\n}\nawait saveGuest(guestData, userId);","typeGuard":"const matchesCustomFieldRegex = (value: string, regexp?: string): boolean =>\n  !regexp || regexp === '' || new RegExp(regexp).test(value);","tryCatchPattern":"try {\n  await saveGuest(guestData, userId);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('error-invalid-custom-field-value')) {\n    // highlight the offending custom field in the form\n  }\n}","preventionTips":["Ship field regexps to the form and validate client-side before submit","Review existing data before tightening a field's regexp","Trim input the same way the server does before validating"],"tags":["omnichannel","custom-fields","regex","validation","visitor","i18n"],"backgroundTag":"regex-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}