{"record":{"id":"a825bd3c5fbeec1b","repo":"medusajs/medusa","slug":"the-email-is-not-valid","errorCode":null,"errorMessage":"The email is not valid","messagePattern":"The email is not valid","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/core/utils/src/common/is-email.ts","lineNumber":23,"sourceCode":"\n/**\n * Check whether provided string is an email.\n * @param email - string to check\n */\nfunction isEmail(email: string) {\n  return email.toLowerCase().match(EMAIL_REGEX)\n}\n\n/**\n * Used to validate user email.\n * @param {string} email - email to validate\n * @return {string} the validated email\n */\nexport function validateEmail(email: string): string {\n  const validatedEmail = isEmail(email)\n\n  if (!validatedEmail) {\n    throw new MedusaError(\n      MedusaError.Types.INVALID_DATA,\n      \"The email is not valid\"\n    )\n  }\n\n  return email.toLowerCase()\n}\n","sourceCodeStart":5,"sourceCodeEnd":31,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/core/utils/src/common/is-email.ts#L5-L31","documentation":"validateEmail uses the isEmail check (validator-style) and throws MedusaError INVALID_DATA when the string is not a syntactically valid email. Used in order/customer update flows and workflows.","triggerScenarios":"Calling an API or workflow with `email: \"foo\"`, undefined coerced to string, or emails with spaces/invalid characters; e.g. POST /store/customers/me with a bad email.","commonSituations":"Missing client-side validation on checkout forms, whitespace in input, test fixtures with placeholder emails like \"test\".","solutions":["Validate email format on the client/edge before calling the API","Trim input and check for empty string before submitting","Use zod/validator in your route or subscriber before invoking workflows"],"exampleFix":"// before\nawait sdk.store.updateCustomer({ email: input })\n// after\nconst email = z.string().email().parse(input)\nawait sdk.store.updateCustomer({ email })","handlingStrategy":"validation","validationCode":"import { isEmail } from \"@medusajs/framework/utils\"\nif (!email || !isEmail(email.trim())) throw new Error('invalid email')","typeGuard":"import { isEmail } from '@medusajs/framework/utils'\nconst isValidEmail = (v: unknown): v is string => typeof v === 'string' && isEmail(v.trim())","tryCatchPattern":"try { await workflow.run({ input }) } catch (e) { if (e.type === 'invalid_data' && /email/.test(e.message)) return res.status(400).json({ message: 'Invalid email' }); throw e }","preventionTips":["Validate email format client-side on all forms","Trim input before submission"],"tags":["email","validation","input"],"backgroundTag":"invalid-email-format","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}