Code & Snippets

Clean Title for Drive / File Creation.

Strip non-alphanumeric characters from a title so it becomes a safe filename for SharePoint, Google Drive, or any file system — drop-in for a Zapier 'Run JavaScript' step.

Pure Operations
JavaScript · 9 lines
C.1

Download

Grab the source file. Drop it into your service, set the required environment variables, and deploy.

C.2

How it works

The gist

Takes an incoming title (from Zapier, a webhook, etc.) and strips out every character that isn't a letter, number, or space. The result is a "drive-safe" string that won't throw errors when used as a filename in SharePoint, Google Drive, or any system that chokes on punctuation, emojis, or special characters.

The flow

  1. InputinputData.title (e.g. an article or deal name pulled from another step).
  2. Sanitize. A single regex replaces everything that is not a-z, A-Z, 0-9, or a space with an empty string.
  3. Trim. Removes leading/trailing whitespace left after stripping.
  4. Returncleaned_title as a single discrete field, ready to map straight into a "Create File" or "Create Folder" action.

Why this exists

SharePoint (and several other document systems) will reject or error on filenames containing certain special characters, emojis, or odd unicode. Instead of debugging cryptic API errors after the fact, this one-liner cleans the name upstream so the downstream file creation always succeeds.

C.3

Source

Full source, exactly as shipped. The download above is byte-identical.

clean_drive_title.jsJavaScript
// inputData.title is the incoming article title from Zapier
const title = inputData.title || "";

// Replace any character that is not a letter, number, or space
const cleaned = title.replace(/[^a-zA-Z0-9 ]+/g, "").trim();

// Return to Zap
return { cleaned_title: cleaned };